Swift 4 Help Needed | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Swift 4 Help Needed

I'm creating the ToDo List app on Swift fundamentals this is the viewcontroller.swift code that is supposed to be a method to determine whether the "Save" button on my app has been tapped and then creates the appropriate item object: override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if sender as AnyObject? === saveButton { let name = nameTextField.text ?? "" item = Item(name: name) } } The problem tho, is that I have an error on let name = nameTextField.text ?? "" that says i'm using an unresolved identifier 'nameTextField'. . . How do I fix this?

18th Jan 2018, 7:24 AM
xx$yn - avatar
1 Answer
Use the same name that you defined for your text field instead of nameTextField, In my case. I named it textFieldTodoList For eg: in viewcontroller.swift look for, @IBOutlet weak var textFieldTodoList: UITextField! .... Below in the function, let name = textFieldTodoList.text ?? “”
12th Feb 2018, 9:33 AM
Farhan Ullah
Farhan Ullah - avatar