I’ve just figured out why some code has just failed to work. I’ve got something like the following:
@interface Client : NSObject {
Connection *connection;
}
@property (retain) NSMutableDictionary *channels;
Followed by this implementation:
@implementation Client
@synthesize channels;
- (id)init
{
self = [super init];
if (self) {
// do whatever I want
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
}
return self;
}
Any idea why channels has a memory address of 0x0 in the init constructor for this class? I can’t figure out for the life of me why this is happening. I’m definitely calling that constructor, and it should be synthesizing the property allowing me to do whatever I want with it.
Unless you explicitly set
channelsto a value, it will remainnil. Perhaps you meant to do the following in yourinitmethod?Two more ways to set channels:
Note that in that case, because we are using your
retainaccessors, we use the autoreleased+dictionaryrather thanalloc/init, which would leak if not using ARC.Of course,
channelsmust also be properly released in-dealloc, if not using ARC: