On Sep 4, 2008, at 5:40 PM, steph thirion 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.

char* getterName = sel_getName(getterSelector);

char * setterName = ... ? ...

SEL setterSelector = sel_getUid(setterName);


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.

Hi!

Two functions that you may consider are:

        NSStringFromSelector()

        NSSelectorFromString()


The first, per its name, will create an NSString out of a SEL variable, while the second will reverse the process. Thus, for a selector of balloonColor (for example) you could have:

SEL getterSel = @selector(balloonColor);
NSString *getterName = NSStringFromSelector(getterSel);
NSString *setterName = [@"set" stringByAppendingString:getterName];
SEL setterSel = NSSelectorFromString(setterName);


This is probably one of the easiest Cocoa ways to do what you want, at least using the steps that you have outlined. There may of course be an easier way to do it but without knowing the specifics of your situation it's harder to tell what might be more suited to your situation. Hope this helps!

Cheers,
        Andrew


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to