Memory management for "id<ProtocolName> variableName" type properties
I'm having a problem with properties of the following type:
id<ProtocolName> variableName;
.....
.....
@property (nonatomic, retain) id<ProtocolName> variableName;
I can access and use them just fine, but when I try to call
[variableName release];
I get compiler warnings:
'-release' not found in protocol(s)
Do I need to define a release method in the interf开发者_StackOverflow社区ace, or how do I release the memory reserved for the variable?
Thanks!
Make your protocol adopts NSObject.
@protocol ProtocolName <NSObject>
...
release
is in the NSObject protocol, so you can declare it as id<ProtocolName, NSObject>
to work within the type system or cast it to a plain id
to stop its class from being typechecked.
You can always add NSObject
to the protocol list.
精彩评论