Xcode 7 beta NSURLConnection 错误
Xcode 7 beta NSURLConnection error
我在我的服务器中调用一个函数,但应用程序崩溃了,但它在模拟器上运行良好。
我的代码:
class func changeTweet(tweet:String)
{
let data = NSMutableData()
let urlPath: String = "http://127.0.0.1:5000/registerword?word=\(tweet)"
let url: NSURL = NSURL(string: urlPath)!
var request = NSMutableURLRequest(URL: url)
let request1: NSURLRequest = NSURLRequest(URL: url)
let response: AutoreleasingUnsafeMutablePointer<NSURLResponse?
>=nil
//crashes on this line:
let dataVal: NSData = try! NSURLConnection.sendSynchronousRequest(request1, returningResponse: response)
var err: NSErrorPointer
let string = NSString(data: dataVal, encoding: NSUTF8StringEncoding)
if let str = string
{
print("Server Response: \(str)")
}
}
试试这个:
让数据:NSData = 试试! NSURLConnection.sendSynchronousRequest(请求,返回响应:&response)
我想你需要的是响应前面的&。
我在我的服务器中调用一个函数,但应用程序崩溃了,但它在模拟器上运行良好。 我的代码:
class func changeTweet(tweet:String)
{
let data = NSMutableData()
let urlPath: String = "http://127.0.0.1:5000/registerword?word=\(tweet)"
let url: NSURL = NSURL(string: urlPath)!
var request = NSMutableURLRequest(URL: url)
let request1: NSURLRequest = NSURLRequest(URL: url)
let response: AutoreleasingUnsafeMutablePointer<NSURLResponse?
>=nil
//crashes on this line:
let dataVal: NSData = try! NSURLConnection.sendSynchronousRequest(request1, returningResponse: response)
var err: NSErrorPointer
let string = NSString(data: dataVal, encoding: NSUTF8StringEncoding)
if let str = string
{
print("Server Response: \(str)")
}
}
试试这个:
让数据:NSData = 试试! NSURLConnection.sendSynchronousRequest(请求,返回响应:&response)
我想你需要的是响应前面的&。