2

I have a protocol that is defined like this:

@protocol Container

- (BOOL)putStuff: (Stuff *) theStuff;

@end

and class with following declaration:

@interface Stuff : NSObject {

}

@property(readwrite,nonatomic,retain) NSObject <Container> * containerHoldingMe;

@end

and I get an error on putStuff declaration — "Expected a type". If I change the argument of the method to NSObject, however, it compiles OK — so, I think that Objective C just doesn't allow loop dependence.

In real classes that I'm working at I want to implement two- However, how do I implement such logic without it?

2 Answers 2

8

By the time the compiler evaluates your Container protocol, it does not know about your Stuff class. You can let the compiler know about your Stuff class with a forward declaration:

@class Stuff;

@protocol Container

- (BOOL)putStuff: (Stuff *) theStuff;

@end
0
0

You should use id here.

@property (readwrite, nonatomic, retain) id<Container> containerHoldingMe;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.