• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Send msg to object by nameed NSString;
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Send msg to object by nameed NSString;


  • Subject: Re: Send msg to object by nameed NSString;
  • From: Daniel DeCovnick <email@hidden>
  • Date: Fri, 20 Jun 2014 02:13:16 -0700


On Jun 18, 2014, at 4:54 PM, Graham Cox <email@hidden> wrote:

>
> On 19 Jun 2014, at 4:53 am, Daniel DeCovnick <email@hidden> 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@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Send msg to object by nameed NSString;
      • From: Trygve Inda <email@hidden>
    • Re: Send msg to object by nameed NSString;
      • From: Graham Cox <email@hidden>
References: 
 >Send msg to object by nameed NSString; (From: Trygve Inda <email@hidden>)
 >Re: Send msg to object by nameed NSString; (From: Daniel DeCovnick <email@hidden>)
 >Re: Send msg to object by nameed NSString; (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Advice on document handling
  • Next by Date: Re: Bindings setup with NSCollectionViews
  • Previous by thread: Re: Send msg to object by nameed NSString;
  • Next by thread: Re: Send msg to object by nameed NSString;
  • Index(es):
    • Date
    • Thread