【发布时间】:2020-01-04 15:03:10
【问题描述】:
在我的项目中,我无法访问要用于每个循环的“楼层”。我需要计算环路中建筑物的楼层数。
// MARK: - UcmData
struct UcmData: Codable {
let buildings: [Building]
}
// MARK: - Building
struct Building: Codable {
let id: Int
let title, subtitle, info, image: String
let floor: [Floor]
}
// MARK: - Floor
struct Floor: Codable {
let number: Int
let title, subtitle, image: String
}
import SwiftUI
import Foundation
struct NamJHerduView: View {
let ucmData = Bundle.main.decode(UcmData.self, from: "ucm_data.json")
var body: some View {
ScrollView {
VStack {
ForEach(0 ..< ucmData.) //here i need to count floors and use maybe where clause to filter just floors from a special building
【问题讨论】:
-
您的数据可能包含许多建筑物。 你想要哪个楼的楼层?
-
假设它将基于建筑物的 id 或标题,我的数据中有 6 个建筑物