tags:

views:

30

answers:

0

Apologies if this is a basic question, I am just starting with Objective-C and trying to wrap things around in my head!

I have a simple class of the form:

@interface Whatever : NSObject {
    int somePrimitive;
    SomeObject* someObject;
}

@property (nonatomic) int somePrimitive;
@property (nonatomic, retain) SomeObject* someObject;

The class is more involved that this, but this illustrates the purpose. When I store instances of this class in a NSMutableDictionary:

Whatever *whatever = [[Whatever alloc] init];
whatever.somePrimitive = 1;
whatever.someObject = ...;
[myDictionary setObject:whatever forKey:@"someKey"];

and then try to retrieve the object later:

Whatever *result = [myDictionary valueForKey:@"someKey"];

then,

result.someObject is ok to reference

but,

result.somePrimitive crashes.

Does the NSDictionary not copy over the primitives of the object? Is the rule that the object stored in a dictionary should only contain objects?