Reputation: 26223
A quick question if I may, can anyone explain what I am missing below, I was assuming the 3rd one with the would work?
@interface ...
// These work
@property(assign) SomeClass *someDelegate;
@property(assign) id someDelegate;
// This gives warning
@property(assign) id <SomeClassDelegate> someDelegate;
.
@implementation ...
@synthesize someDelegate;
[self setSomeDelegate:[[SomeClass alloc] init]];
[someDelegate setDelegate:self];
.
warning: method '-setDelegate:' not found (return type defaults to 'id')
// SomeClass.h
#import <Foundation/Foundation.h>
@class SomeClass;
@protocol SomeClassDelegate <NSObject>
@optional
-(void)didHappen:(SomeClass *)someClass;
@required
-(void)willUse:(SomeClass *)someClass withThis:(BOOL)flag;
@end
@interface SomeClass : NSObject {
id <SomeClassDelegate> delegate;
}
@property(assign) id <SomeClassDelegate> delegate;
-(void)otherActions;
@end
cheers Gary.
Upvotes: 1
Views: 2843
Reputation: 8810
Go protocols!
@protocol MyDelegateProtocol
- (NSNumber*) someFunction:(NSArray*) anArray;
@end
@interface MyClass : NSObject {
id<MyDelegateProtocol> delegate;
}
@property id<MyDelegateProtocol> delegate
@end
Then in your @implementation:
@synthesize delegate;
As far as I know, the Cocoa way :-)
Cheers
Nik
Upvotes: 3
Reputation: 49354
Unless it exists and you didn't show it, you don't have a setDelegate
method. You have a setSomeDelegate
method, though.
Upvotes: 0