Error: cannot use instance in property initializer - Swift 3

When I compile the following code, I get the error “Unable to use an instance of“ AddEployeeName ”in the property initializer, property initializers run before“ self'is available. ”Can you help with this error? The program should allow the employee to be able to enter his name and take pictures:

class AddEmployeeViewController: UITableViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate { @IBOutlet weak var addEmployeeName: UITextField! @IBOutlet weak var addEmployeeEmail: UITextField! @IBOutlet weak var employeePhoto: UIImageView! let employee: [String:AnyObject] = [ "name": addEmployeeName.text!, "email": addEmployeeEmail.text!, ] 
+4
source share
1 answer

You cannot call addEmployeeName.text! inside property initializers. However, you can initialize "employee" within a method, such as viewDidLoad

+5
source

Source: https://habr.com/ru/post/1270402/


All Articles