1

Hello i am facing a Small Problem with usurlsession.

here is my code

NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];

NSURLSessionDataTask * dataTask = [_defaultSession dataTaskWithURL:url
                                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                    if(error == nil)
                                                    {
                                                        NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
                                                        NSLog(@"Data = %@",text);
                                                        [self.delegate networkconnectionThreadstatus:self.ResponseStr withdata:Responsedata];
                                                    }

                                                }];

[dataTask resume];

This works fine if i use this in UIViewController Class but i am trying to use in NSObject class and getting this error this "Sending 'networkConnection *const __strong' to parameter of incompatible type 'id _Nullable', on Delegate :self

Can Someome please help me to resolve this , i am very new to this . Thanks you .

akshat
  • 59
  • 3
  • how u r calling this in the NSObject class from your view controller class ? – Teja Nandamuri May 10 '16 at 17:32
  • 1
    Have you declared your NSObject subclass as conforming to the delegate protocol? – danh May 10 '16 at 18:01
  • Two classes want to speak together.The `NSURLSession` class and I assume your `viewcontroller` class are the 2 classes. You have to tell the `NSURLSession` "hey, delegate handling stuff to this viewcontroller, because I'm only a blueprint I can make the NSURLSession work, but you have to guide me *how*"... and **in return** you must tell the `viewController` to **conform** to to `NSURLSession` protocol. I assume you haven't done that. – mfaani May 10 '16 at 19:58
  • You just have to add to your interface **so that the other class would be able to know how to send/receive/speak to the NSURLSession, otherwise it would be dumbfounded on how to speak/recieve/send messages**. See [this](https://www.raywenderlich.com/46988/ios-design-patterns) and http://stackoverflow.com/questions/5431413/difference-between-protocol-and-delegates – mfaani May 10 '16 at 19:59

0 Answers0