简体   繁体   中英

How do I get rid of this warning in iOS 7 Objective-C?

I have the following code for NSURLSession

NSURL * url = [NSURL URLWithString:urlString];
HomeViewController* hvc= [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate:hvc delegateQueue:    [NSOperationQueue mainQueue]];
NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithURL:url ];
[dataTask setAccessibilityLabel:@"UserProfiling"];
[dataTask resume];

The compiler shows a warning at this statement:

NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate:hvc delegateQueue: [NSOperationQueue mainQueue]];

and the warning is :

Sending 'HomeViewController *' to parameter of incompatible type 'id<NSURLSessionDelegate>'

How do I remove this warning?

I have confirmed to the delegates by writing:

@interface ProfileTabView : UIViewController <NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate>
{

}

Basically, I am calling a NSURLSessionDataTask and the delegates are in another ViewController as you see above.

(From a comment, making answer for posterity.)

HomeViewController is not the class you've added the protocol conformance to (ProfileTabView).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM