5

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!,

    ]
0

1 Answer 1

5

You can't call addEmployeeName.text! within property initializers. You can however initialize 'employee' within a method like viewDidLoad

Sign up to request clarification or add additional context in comments.

1 Comment

Another point is the Dictionary type should be [String: Any] in Swift 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.