On Jun 18, 2014, at 4:54 PM, Graham Cox <[email protected]> wrote:

> 
> On 19 Jun 2014, at 4:53 am, Daniel DeCovnick <[email protected]> wrote:
> 
>> Yes. You can either use key-value coding: [[self valueForKey:myString] 
>> release];
> 
> 
>> [value release];
> 
> 
> 
> These invocations of -release appear to be erroneous. Why do you have them 
> there? If you think they should be there as a matter of routine, your 
> understanding of memory management is probably faulty.


I'm following the example in the original message:

> [myNumber release];
> 
> I could do something like:
> 
> [getProperty(myString) release];

Your first thought is I don’t know memory management? That’s really not very 
charitable of you. 


Back on topic:

> 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.

It’s not just an advantage, it’s avoiding a crasher, most likely, and where 
it’s not, it’s avoiding silently corrupting an object graph. [(id)someInt 
release] is not a message you want to ever find yourself sending. 

> So this would be better?
> 
> for (NSString* key in [self propertyKeys])
> [self setValue:nil forKey:key];


No, because unless you also override -setNilValueForKey: for your classes that 
do this, you will raise an NSInvalidArgumentException. 

>  If you are relying on synthesizing the actual ivar, not just the 
> setters/getters, you have little choice, though apparently you can rely on 
> the ivar being the name of the property with a leading underscore. I dislike 
> that sort of hidden magic however.

Implicit synthesis creating an ivar with a leading underscore is well 
documented and hardly hidden magic. Declare your ivars for synthesized 
properties or don’t, they’ll be available either way, with a leading underscore 
if implicit synthesis is used, without if an explicit @synthesize is used.

Daniel


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to