Reputation: 1721
I need to fetch a NSString from the NSMutableDictionary and assign it to UITextField's text.
But I am getting an exception ; unexpectedly found nil while unwrapping an Optional value
When I log the string it writes to console.
My code is as below;
let tempString:NSString! = tempDict.objectForKey("name") as? NSString
NSLog("%@",tempString)
cell.textLabel.text = tempString //This line gives the exception
Upvotes: 0
Views: 1366
Reputation: 1
You can Try This. It Helped to get out from the same problem I was having
let userName : NSString = result.valueForKey("name") as! NSString self.lblUserName.text = userName as String
Upvotes: 0
Reputation: 11197
You stop this by safely unwrapping cell.textLabel by adding an if statement.
if var label = cell.textLabel{
label.text = "This is a title"
}
Hope this helps.. :)
Upvotes: 1