gpt4 book ai didi

xcode - Swift 2 字符串和 NSURL 错误

转载 作者:行者123 更新时间:2023-11-28 13:01:55 25 4
gpt4 key购买 nike

更新到 Swift2 后,我收到一些我不理解的错误:

第一个错误:

 if(!parole1.text.isEmpty && !parole2.text.isEmpty && !parole3.text.isEmpty && isValidEmail(parole4.text)){

... code
}

--> ERROR: *Value of optional type String? not unwrapped!*

第二个错误:

var dataString = "name="+name.text+"&name2="+Name2.text+"&parola="+parola.text+"&pwd="+pwd.text

--> ERROR: *Expression was too complex to be solved in reasonable time*

第三个错误:

let reply = NSURLConnection.sendSynchronousRequest(request, returningResponse:&response, error:&error)

-->ERROR: *Extra argument 'error' in call*

最佳答案

第一个错误:

parole1.text 是可选的,必须用 ?或者 !在你调用 isEmpty 之前。

第二个错误:

我不确定为什么这对 swift 来说是个问题,但它可以用像这样的格式化字符串来解决:

var dataString = "name=\(name.text)&name2=\(Name2.text)&parola=\(parola.text)&pwd=\(pwd.text)"

但是您可能还想使用 if let 或 hard 解压此处的文本!

第三个错误:

NSURLConnection.sendSynchronousRequest 不再将错误作为参数。

do {
let reply = try NSURLConnection.sendSynchronousRequest(request, returningResponse:&response)
} catch {

}

编辑:改用 NSURLSessionNSURLConnection.sendSynchronousRequest 已弃用

关于xcode - Swift 2 字符串和 NSURL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33646387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com