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

蹲街弑〆低调 提交于 2019-12-01 17:48:06

问题


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

    ]

回答1:


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



来源:https://stackoverflow.com/questions/40710909/error-cannot-use-instance-member-within-property-initializer-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!