Reputation: 4122
I have this variable:
var fetchedImagesArray: [String] = []
Then I fetch an array of images name from my server using Alamofire and SwiftyJson like this:
if let fetchedImages = json["images"].arrayObject {
fetchedImagesArray = fetchedImages
}
But I get the error here fetchedImagesArray = fetchedImages saying: cannot assign value of type anyobject to type string.
The array returned loooks like this ["imgName1","imgName2","imgName3"] which is all strings to why cant I set fetchedImagesArray?
Upvotes: 2
Views: 6096
Reputation: 285069
In SwiftJSON
the property arrayObject
returns [AnyObject]?
so you have to downcast the array to its actual type
if let fetchedImages = json["images"].arrayObject as? [String] {
fetchedImagesArray = fetchedImages
}
Upvotes: 3