> 
> On 19 Jun 2014, at 10:57 am, Trygve Inda <cocoa...@xericdesign.com> wrote:
> 
>> The method propertyKeys (below) is used to simplify and shorten the code in
>> these classes since I want to encode/decode and (upon dealloc), release all
>> the properties.
> 
> 
>> -(void)dealloc
>> {
>>    for (NSString* key in [self propertyKeys])
>>        [[self valueForKey:key] release];
> 
> 

> Ideally, your -dealloc method should mirror your -init method, so that you
> have each property set to nil listed individually, just as -init sets each one
> individually. Sure, that's tedious if you have hundreds of properties, but
> it's at least reliable with no nasty surprises. If you are determined to
> iterate a list, then at least use the setter, passing nil, rather than the
> getter, and calling release. (That also allows you to change a property to
> 'assign' or 'copy' if necessary without creating a bug).


I would think 'copy' would still be ok with this (for example in the case of
NSStrings) since that should still be released. For 'assign' I can see the
advantage.

So this would be better?

for (NSString* key in [self propertyKeys])
 [self setValue:nil forKey:key];


I can't at all see how I would ever subclass this, but I'll certainly give
the rest of your post some serious thought. Obviously if I ever do need to
subclass, I'll have to revert to listing each property on its own for
code/decode and dealloc.

Thanks,

Trygve





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to