Reputation: 123
When I compile the following code I get an error "Cannot use instance member 'AddEployeeName' within property initializer, property initializers run before 'self'is available". Can you help with this error? The program is to allow an employee to be able to enter in their name and take their photo:
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!,
]
Upvotes: 5
Views: 15834
Reputation: 1056
You can't call addEmployeeName.text!
within property initializers. You can however initialize 'employee' within a method like viewDidLoad
Upvotes: 5