2016-11-21 37 views
3

當我編譯下面的代碼時,出現錯誤「無法在屬性初始值設定項中使用實例成員'AddEployeeName',屬性初始值設定項在'self'is available'之前運行。你能幫助解決這個錯誤嗎?該計劃是爲了讓員工能在他們的名字進入,並採取他們的照片:「!addEmployeeName.text」錯誤:無法在屬性初始值設定項中使用實例成員Swift 3

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

    ] 

回答

4

你不能打電話屬性初始值設定項中。你可以用另一種方法初始化'員工',例如viewDidLoad

+2

另一點是Swift 3中字典類型應該是[String:Any] –

+0

@LeoDabus好點,我忘了提到這一點。 – damiancesar

+0

很好的答案,非常感謝! – Fozoro

相關問題