• 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: string convertion: converting getter name to setter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string convertion: converting getter name to setter


  • Subject: Re: string convertion: converting getter name to setter
  • From: Phil <email@hidden>
  • Date: Fri, 5 Sep 2008 13:34:23 +1200

On Fri, Sep 5, 2008 at 12:40 PM, steph thirion <email@hidden> wrote:
>
> from the selector of a given getter function, I need to get the selector of
> the equivalent setter function. For instance, from color I should get
> setColor.
>

I assume you want to do more with the selector than just invoke
it---otherwise you can just use KVC and save yourself some grief.
There are a few cases you may encounter here:
 1. There is no setter.
 2. There is a setter and the class is KVC compliant for the key.
 3. There is a setter and the class isn't KVC compliant for the key,
but there is a setter defined as part of a property definition.
 4. (3) but without the property definition.

> char* getterName = sel_getName(getterSelector);
>

Instead of using C strings, you can use NSStrings and
NSSelectorFromString() and NSStringFromSelector()---making string
manipulation much easier. However, for case (3), you'll need to do
some parsing of the property attribute list from
property_getAttributes().

> What would be the less costly way, performance wise, to convert the C string
> "color" to "setColor"?
>
> I have no experience in working with strings in objc, and was hoping someone
> would point me in the right direction before I start.

If you're working in Cocoa (and I assume you are, since this is a
cocoa-dev list), this is a good starting point:
<http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/>

Phil
_______________________________________________

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: string convertion: converting getter name to setter
      • From: steph thirion <email@hidden>
References: 
 >string convertion: converting getter name to setter (From: steph thirion <email@hidden>)

  • Prev by Date: Re: string convertion: converting getter name to setter
  • Next by Date: Re: string convertion: converting getter name to setter
  • Previous by thread: Re: string convertion: converting getter name to setter
  • Next by thread: Re: string convertion: converting getter name to setter
  • Index(es):
    • Date
    • Thread