void函数中的意外非void返回值(swift4.0.3)

时间:2018-02-01 16:13:57

标签: ios

override func viewDidLoad() {

    super.viewDidLoad()
    self.navigationItem.title = "Login"
    self.view.backgroundColor = UIColor.blue

    //Mark:- making UITextFeild

    let UserName: UITextField
    let tf = UITextField()
    tf.borderStyle = .none
    tf.layer.cornerRadius = 5
    tf.backgroundColor = UIColor()
    tf.textColor = UIColor(white: 0.9, alpha: 0.5)
    tf.font = UIFont.systemFont(ofSize: 17)
    tf.autocorrectionType = .no

    //Mark:- PlaceHolder

    var placeholder = NSMutableAttributedString()
    placeholder = NSMutableAttributedString(attributedString: NSMutableAttributedString(string: "UserName", attributes: [.font:UIFont.systemFont(ofSize: 18)]))
   tf.attributedPlaceholder = placeholder
    return tf
    //This Error:-Unexpected non-void return value in void function after when I return tf
}

1 个答案:

答案 0 :(得分:1)

从外观来看,你试图用tf定义838123 8 12 作为计算变量,应该在这样的块中完成:

UserName

请注意额外的大括号。

UserName也需要成为var,因为你不能将一个计算类型用于let变量。

另外值得一提的是,UserName将完全是viewDidLoad方法的本地方法,而不是添加到视图层次结构中,但这可能只是因为有更多代码未显示或尚未添加。

相关问题