2

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?

1
  • 2
    Have you tried if let fetchedImages = json["images"].arrayObject as [String] Commented Sep 13, 2016 at 15:12

1 Answer 1

3

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.