错误:无法在属性初始化程序中使用实例成员-Swift 3 [英] Error: Cannot use instance member within property initializer - Swift 3

查看:206
本文介绍了错误:无法在属性初始化程序中使用实例成员-Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编译以下代码时,出现错误无法在属性初始化程序中使用实例成员'AddEployeeName',属性初始化程序在'self'可用之前运行".您可以协助解决此错误吗?该计划允许员工输入他们的姓名并拍摄照片:

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

    ]

推荐答案

您不能在属性初始值设定项中调用addEmployeeName.text!.但是,您可以在诸如viewDidLoad

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

这篇关于错误:无法在属性初始化程序中使用实例成员-Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆