I was trying to get some JSON data from a Flickr API but my Swift code is not working.
This is based on Jameson Quave's tutorial on making an API request with Swift
func GetFlickrData(tags: String) {
let baseURL = "https://api.flickr.com/services/rest/?&method=flickr.photos.search"
let apiString = "&api_key=\(apiKey)"
let searchString = "&tags=\(tags)"
let requestURL = NSURL(string: baseURL + apiString + searchString)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(requestURL, completionHandler: { data, response, error -> Void in
var result = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as NSDictionary
dispatch_async(dispatch_get_main_queue(), {
println(result)
})
})
task.resume()
}
This shows me an error for the requestURL argument that says: "Vaue of type NSURL? not unwrapped". When I add "!", the error goes away. But, I still get a runtime error when making the call.
In the debugger, I see:
data = (NSData!)16642 bytes
fatal error: unexpectedly found nil while unwrapping an Optional value
What am I missing?
EDIT - This was working fine on Xcode 6, it broke when updating Xcode to version 6.1