简体   繁体   English

Xcode-建筑应用-问题

[英]Xcode - Building App - Issue

I'm learning how Swift works and I'm stuck where the user will have to login with a username and password: 我正在学习Swift的工作原理,并且卡在用户必须使用用户名和密码登录的位置:

@IBAction func loginAction(_ sender: AnyObject) {

    var username = self.usernameField.text
    var password = self.passwordField.text

    if (username.utf16Count < 4 || password.utf16Count < 5) {

        var alert = UIAlertView(title: "Invalid", message: "Username must be greater then 4 and Password must be greater than 5.", delegate: self, cancelButtonTitle: "ok"  )
        alert.show()
    }else {
        self.actInd.startAnimating()
    }

This is what I've got, but Xcode is stating 这就是我所拥有的,但是Xcode正在说明

if (username.utf16Count < 4 || password.utf16Count < 5)

is incorrect. 是不正确的。

Can someone explain why it's wrong? 有人可以解释为什么错了吗?

I'm using Xcode v8.0. 我正在使用Xcode v8.0。

It should be: 它应该是:

  if (username?.utf16.count)!<4 || (password?.utf16.count)!<5{  }

Also the other thing you should do is to check if the username and password fields contain valid characters, for instance would you like users to be able to enter emojis/certain symbols/characters other than those in the English language, as part of their username/password? 另外,您应该做的另一件事是检查用户名和密码字段中是否包含有效字符,例如,您是否希望用户能够输入除英语以外的表情符号/某些符号/字符作为用户名的一部分/密码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM