2
I am unable to assign a textField with the result of a search when it is int, with the right string
var results:NSArray = try context.executeFetchRequest(request) as! [NSManagedObject]
if(results.count > 0){
var res = results[0] as! NSManagedObject
nomeText.text = res.valueForKey("nome") as? String
idadeText.text = res.valueForKey("idade") as? String
print(res.valueForKey("idade") as? String)
}
In the print it returns me nil.. when it changes to Int, it returns me correct value.. how do I assign the textField with this value, remembering that with the field name I do not have this error
Thanks for the help Fernando, I knew it would have to be the as? Int, I just wasn’t able to put in textField. I followed your advice and it worked I just had to put ! in idadeText.text = res.idade!. Description
– Fábio Reibnitz
the "!" sign is required if your attribute is marked as Optional (a "?" next to the type), in which case you can keep the nil value. Through the graphical interface of the xcdatamodel file, you can customize this.
– Fernando Mondo
I read more about it here http://themsaid.github.io/2015/04/16/core-data-from-scratch-with-swift/ Thank you again
– Fábio Reibnitz