Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot use instance member within property initializer - Swift 3

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

    ]
like image 390
Ronnie L Avatar asked Nov 21 '16 00:11

Ronnie L


1 Answers

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

like image 166
dispatchswift Avatar answered Sep 23 '22 08:09

dispatchswift