import UIKit
protocol HttpProtocol
{
func didReceiveResults(results:NSArray)
}
class HttpController:NSObject{
var delegate:HttpProtocol?
func onSearch(url:String){
var nsUrl:NSURL = NSURL(string:url)!
var request:NSURLRequest = NSURLRequest(URL:nsUrl)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler:{ (response:NSURLResponse!,data:NSData!,error:NSError!)
-> Void in
var httpResponse = response as! NSHTTPURLResponse
if ( httpResponse.statusCode == 200){
var array:NSArray =
NSJSONSerialization.JSONObjectWithData (data,
options : NSJSONReadingOptions.AllowFragments,
error:nil) as! NSArray
self.delegate?.didReceiveResults(array)
}
})
}
}
报错为:
1.Cannot convert value of type '(NSURLResponse!, NSData!, NSError!) -> Void' to expected argument type '(NSURLResponse?, NSData?, NSError?) -> Void'
2.Extra argument 'error' in call
折腾不下了,这个闭包不知道问题出在哪里。。。。