This is so basic, I'm a little embarrassed to ask, but... I'm retrieving some JSON from my server into these structs:
struct CategoryInfo: Codable {
var categoriesResult: [CategoryDetail]
}
struct CategoryDetail: Codable{
var categoryName: String
var categoryDescription: String
var categorySortOrder: Int
var categoryId: String
}
And now I want to loop over CategoryDetail for each of the few-dozen occurrences, saving them into CoreData. My current attempt looks like this:
let decoder = JSONDecoder()
do {
let categories = try decoder.decode(CategoryInfo.self, from: data!)
for category in [CategoryDetail] {
//... perform the CoreData storage here
}
But I get the error that CategoryDetail either doesn't conform to Sequence or to IterateProtocol, but when I try to implement those, the solution appears, frankly, too complicated. It's just an array... shouldn't I be able to loop over it without a lot of hoohaw (using that in a technical sense, of course)?