@selector and return value
- by user320926
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;
}