Quick fatal error: Null found unexpectedly while expanding optional uiimage value
I have an error and UIImage is assigning an image of a property to the UIImageView
func connectionDidFinishLoading(connection: NSURLConnection!) {
var err: NSError
var jsonResult : NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
println("\(jsonResult)")
if jsonResult.count > 0 {
let homepage = jsonResult.objectForKey("homepage") as NSMutableDictionary
if homepage.count > 0 {
let imageUrl = homepage.objectForKey("url_img") as NSString
let backgroundImageUrl = NSURL.URLWithString(imageUrl)
let backgroundImageData = NSData(contentsOfURL: backgroundImageUrl)
var image :UIImage = UIImage(data: backgroundImageData)
println("\(image)")
self.backgroundImage.image = image
}
}
}
This is the delegate function from the get request.
backgroundImageData
and image
not zero, but it doesn't work, I don't understand.
I am a newbie with Swift: s
This code works with objective-C
NSString *imageUrl = [metaData objectForKey:@"url_img"];
NSURL *backgroundImageUrl = [NSURL URLWithString:imageUrl];
NSData *backgroundImageData = [NSData dataWithContentsOfURL:backgroundImageUrl];
self.backgroundImage.image = [UIImage imageWithData:backgroundImageData];
+3
source to share
1 answer