Here's code:
section.name = (alert.textFields[0] as! UITextField).text
I have an error Cannot assign a value of type String! to a value of type String
section is a Core Data NSManagedObject subclass with required value of name.
Here's code:
section.name = (alert.textFields[0] as! UITextField).text
I have an error Cannot assign a value of type String! to a value of type String
section is a Core Data NSManagedObject subclass with required value of name.
You need to check alert.textFields isn't nil before you can use the subscript. Which you're not doing in your code sample.
In my opinion, the best way to get the value of text is to use optional binding, like so:
if let textField = alert.textFields?[0] as? UITextField {
section.name = textField.text
}
However, if you're absolutely sure your alert has a text field, should see @Arun Gupta's answer.