I have a test class that tries to reach to google with a NSURLConnection. If I try to make it generic, the NSURLConnectionDataDelegate methods are never called.
class Remote<T: NSObject>: NSObject, NSURLConnectionDelegate, NSURLConnectionDataDelegate { //class Remote: NSObject, NSURLConnectionDelegate, NSURLConnectionDataDelegate { var data = NSMutableData() func connect(query:NSString) { var url = NSURL(string:"http://www.google.com")! var request = NSURLRequest(URL: url) var conn = NSURLConnection(request: request, delegate: self, startImmediately: true) } func connection(didReceiveResponse: NSURLConnection!, didReceiveResponse response: NSURLResponse!) { LF.log("didReceiveResponse") } func connection(connection: NSURLConnection!, didReceiveData conData: NSData!) { LF.log("didReceiveData") self.data.appendData(conData) } func connectionDidFinishLoading(connection: NSURLConnection!) { LF.log("didFinished") //println(self.data) } deinit { println("deiniting") } } To test it (comment/uncomment the first/second line to compare):
let remote = Remote<NSObject>() //let remote = Remote() remote.connect("") Any idea please?
Update1: to answer comment 1, it's a REST client that handles network connection and parsing for you. I'd write a blog about this later (since it's still under development), but to give you the idea here's some demo code from my project:
let client = ICRestClient<ICCategoryModel>(api:IC.api.category_list) client.func_array = { (results: [ICCategoryModel]?, error: NSError?) -> Void in block!(results, error) } client.execute() And ICCategoryModel is like:
class ICSubCategoryModel: ICModel { var name: String? var category_id: Int = 0 } The idea is that you pass the API URL in, you get an array (or error) with some reflected objects instead of Dictionary. It's from my LSwift library and supports various authentications methods (buildin-parameters, cookie, header, authentication challenge etc.)