0
斯威夫特ObjectMapper循環我有這樣的映射:嵌套
import Foundation
import ObjectMapper
class Article: Mappable {
var id: Int!
var name: String!
var image: String!
var children: Article!
required init?(_ map: Map) {
mapping(map)
}
func mapping(map: Map) {
id <- map["id"]
name <- map["name"]
image <- map["image"]
children <- map["children"]
}
}
,然後我需要循環,並通過ID找到文章:
func getArticleName(aid) {
for article in articleList {
if aid == article.id {
return article.name
}
for child in article.children {
if aid == child.id {
return child.name
}
}
}
return ""
}
articleList
是Article
可映射類的數組。
現在,當我在環兒,我收到此錯誤: Value of type 'Article' has no member 'Generator'
我怎麼能循環兒童陣列?
這是什麼問題?你不明白那個錯誤信息嗎? – matt
是的,我如何循環兒童數組? –
這不是一個數組。這就是錯誤信息告訴你的。 – matt