我想要做的是檢索json數據(數組格式)並檢查我的本地數組是否已經包含數據,如果它移動直到JSON數據中的下一個值,直到它們是數組不包含的值,然後將其附加到數組。數組中的這些數據必須按順序排列。我試圖做到這一點,但現在得到的錯誤:類型'customDataObject'不符合協議'序列'
Type 'ResultsGenrePosters' does not conform to protocol 'Sequence'
這是什麼樣子:
public struct ResultsGenrePosters: Decodable {
public let results : [GenrePosters]?
public init?(json: JSON) {
results = "results" <~~ json
}
}
public struct GenrePosters: Decodable {
public let poster : String
public init? (json: JSON) {
guard let poster: String = "poster_path" <~~ json
else {return nil}
self.poster = poster
}
static func updateGenrePoster(genreID: NSNumber, urlExtension: String, completionHandler:@escaping (_ details: [String]) -> Void){
var posterArray: [String] = []
let nm = NetworkManager.sharedManager
nm.getJSONData(type:"genre/\(genreID)", urlExtension: urlExtension, completion: {
data in
if let jsonDictionary = nm.parseJSONData(data)
{
guard let genrePosters = ResultsGenrePosters(json: jsonDictionary)
else {
print("Error initializing object")
return
}
guard let posterString = genrePosters.results?[0].poster
else {
print("No such item")
return
}
for posterString in genrePosters {
if posterArray.contains(posterString){continue
} else { posterArray.append(posterString) } //This is where the error happens
}
}
completionHandler(posterArray)
})
}
}
你的命名是一種單/複數混淆;-) – vadian