Reputation: 480
I am trying to loop through array that exists in a dictionary. What am I doing wrong and how should this work?
public func getItemCount() -> Int{
var count = 0
for item in order.object(forKey:"items") as? Array {
count += 1
//other instructions
}
return count
}
Upvotes: 1
Views: 57
Reputation: 5695
Try breaking it down to two steps.
public func getItemCount() -> Int{
if let thisArray:[AnyObject] = order.object(forKey:"items") as? [AnyObject] {
for item in thisArray {
}
}
}
Feel free to suggest edits. Please let me know if it doesn't work
Upvotes: 3