May I ask a few questions relating to this exercise.
1) How would one store an instance variable like "playtime". As an NSString* ( eg "@1 hr 32 mins"?) or perhaps as a number object?
2) We have been taught, up to now ( not yet at GC) how to release, for example, an addressCard with instance variables that have alloced memory.
So, for instance, given a card with a single NSString *name ( for example) the dealloc method would be something like:
and the setter would be *something* like
Now, using synthesized methods:
I **think** that the above will do the same as the release and assign ( with new alloc) in the above code. But what about the release during the "dealloc" method. Will it take care of that?
The reason I ask, is that the documentation says:
If I have not articulated my exact issue, it is that I do not clearly understand it yet myself. Any insight is appreciated
1) How would one store an instance variable like "playtime". As an NSString* ( eg "@1 hr 32 mins"?) or perhaps as a number object?
2) We have been taught, up to now ( not yet at GC) how to release, for example, an addressCard with instance variables that have alloced memory.
So, for instance, given a card with a single NSString *name ( for example) the dealloc method would be something like:
Code:
-(void) dealloc
{
[ theProperty release];
[super dealloc];
and the setter would be *something* like
Code:
-(void) setProp: (NSString *) aProp
{
[theProperty release];
the Property = [ [ class alloc] initWithProp: aProp];
etc etc.
Now, using synthesized methods:
@property ( copy, nonatomic) NSString *theProperty
I **think** that the above will do the same as the release and assign ( with new alloc) in the above code. But what about the release during the "dealloc" method. Will it take care of that?
The reason I ask, is that the documentation says:
Although this works well for strings, it may present a problem if the attribute is a collection such as an array or a set. Typically you want such collections to be mutable, but the copy method returns an immutable version of the collection. In this situation, you have to provide your own implementation of the setter method, as illustrated in the following example.
If I have not articulated my exact issue, it is that I do not clearly understand it yet myself. Any insight is appreciated