views:

70

answers:

2

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')

EDIT_001:

// 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.

A: 

Unless it exists and you didn't show it, you don't have a setDelegate method. You have a setSomeDelegate method, though.

kubi
Hi kubi, setDelegate is on the 3rd line under @implementation.
fuzzygoat
+1  A: 

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

niklassaers
Hi, might I ask how you would instantiate that?
fuzzygoat
Sure, if the protocol is declared in MyClass.h, do in your controller header MyController.h (or wherever you want to use it) #import "MyClass.h", then in the @interface MyController line you add <MyDelegateProtocol> before the {, thus saying that this class implements MyDelegateProtocol. Then all you need is to implement in that class the protocol functions, in this case - (NSNumber*) somefunction:(NSArray*) anArray;
niklassaers