Reputation: 11780
I'm retrieving a list of URL images using Alamofire. The response is in JSON And I have used SwiftyJSON to parse and print each element. I want the URLs to be added into a URL array. Below is the code I have used
var newArray = [URL(string: "http://www.tummyvision.com/users/uploads/[email protected]/photos/4.jpg")]
Alamofire.request("http://www.tummyvision.com/users/login/get-images.php", parameters: parameters).responseData { response in
let json = JSON(data: response.result.value!)
for i in 0..<json.count
{
print(json[i]) // prints the correct url
self.urlArray.append(json[i])
}
}
But it is giving me the following error:
Upvotes: 0
Views: 615
Reputation: 72410
Try to use arrayValue
property of JSON to access array also you need to convert String
Url to URL
object before adding it into Array of URL
.
if let urls = json.arrayValue {
for url in urls {
self.urlArray.append(URL(string:url))
}
}
Upvotes: 2