错误:无法在属性初始值设定项中使用实例成员 - Swift 3

时间:2016-11-21 00:00:28

标签: swift3 instance-variables

当我编译以下代码时,我收到错误"无法使用实例成员' AddEployeeName'在属性初始值设定项中,属性初始值设定项在“自用”之前运行"。你能帮忙解决这个错误吗?该计划允许员工输入他们的名字并拍照:

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 个答案:

答案 0 :(得分:5)

您无法在属性初始值设定项中调用addEmployeeName.text!。但是,您可以初始化员工'在viewDidLoad

之类的方法中