【问题标题】:Value of optional type 'String' not unwrapped; did you mean to use '! or '?' [duplicate]可选类型“字符串”的值未展开;你的意思是用'!或者 '?' [复制]
【发布时间】:2016-08-01 01:25:05
【问题描述】:

我对 swift 很陌生,在下一行遇到了这个错误。

if(userEmail.isEmpty || userPassword.isEmpty || userRepeatPassword.isEmpty)

【问题讨论】:

  • 我不明白他们的代码行和我的代码行之间的区别。我找不到包含多个 if 变量的类似帖子。 (我也是stackoverflow的新手)
  • 另见this answer
  • 完美。谢谢你。抱歉重复的问题。我还在学习。

标签: swift


【解决方案1】:

试试这个:

guard let userEmail = userEmail where !userEmail.isEmpty else {

    print("oh oh")
    return
}

您可以将所有验证测试合并到一个守卫中,但它们可能会变得很长。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    • 2015-10-30
    相关资源
    最近更新 更多