Cesar
Cesar

Reputation: 4437

@selector and return value

The idea it's very easy, i have an http download class, this class must support the http authentication but it's basically a background thread so i would like to avoid to prompt directly to the screen, i would like to use a delegate method to require from outside of the class, like a viewController.

But i don't know if is possible or if i have to use a different syntax.

This class use this delegate protocol:

//Updater.h
@protocol Updater <NSObject>
-(NSDictionary *)authRequired;
@optional
-(void)statusUpdate:(NSString *)newStatus;
-(void)downloadProgress:(int)percentage;
@end



@interface Updater : NSThread {
...
}

This is the call to the delegate method:

//Updater.m
// This check always fails :(
if ([self.delegate respondsToSelector:@selector(authRequired:)]) { 
    auth = [delegate authRequired];
}

This is the implementation of the delegate method

//rootViewController.m
-(NSDictionary *)authRequired;
{
    // TODO: some kind of popup or modal view
    NSMutableDictionary *ret=[[NSMutableDictionary alloc] init]; 
    [ret setObject:@"utente" forKey:@"user"];
    [ret setObject:@"password" forKey:@"pass"];
    return ret;
}

Upvotes: 0

Views: 2117

Answers (1)

kennytm
kennytm

Reputation: 523444

if ([self.delegate respondsToSelector:@selector(authRequired:)]) { 

In ObjC, the colons (:) in the method name is significant. That means authRequired and authRequired: are different methods. Try this instead:

if ([delegate respondsToSelector:@selector(authRequired)]) {

Upvotes: 1

Related Questions