On 18 Oct 2011, at 00:29, glenn andreas wrote: > > On Oct 16, 2011, at 1:58 AM, Gerriet M. Denkmann wrote: > >> I have this code: >> >> for( id aThing in someArray ) >> { >> if ( [ aThing respondsToSelector: @selector(setTitle:) ] ) >> { >> [ self replaceIn: aThing >> readSelector: @selector(title) >> writeSelector: @selector(setTitle:) >> withTable: tableName >> ]; >> } >> } >> >> >> - (void)replaceIn: thing readSelector: (SEL)selectorIn writeSelector: >> (SEL)selectorOut withTable: (NSString *)tableName; >> { >> NSString *key = [ thing performSelector: selectorIn ]; >> ... >> NSString *rep = ... >> [ thing performSelector: selectorOut withObject: rep ]; >> } >> >> Now, using Arc I am told that "PerformSelector may cause a leak because its >> selector is unknown". >> What I am supposed to do about this? I really want to have code without >> warnings. > > > Based on your samples, why not change this to just use KVC instead? > > for (id aThing in someArray) > if ([aThing respondsToSelector: @selector(setTitle:)]) { // too bad > there isn't a cleaner way to ask [aThing hasKey: @"title"] > [ self replaceIn: aThing key: @"title" withTable: tableName ]; > } > } > > - (void) replaceIn: (id) thing key: (NSString *) ivarKey withTable: (NSString > *) tableName > { > NSString *key = [thing valueForKey: ivarKey]; > ... > NSString *rep = ... > ... > [ thing setValue: rep forKey: ivarKey]; > } >
This looks like a very good idea. I will try it tomorrow. How does: > NSString *key = [thing valueForKey: ivarKey]; compare performance-wise with: >> NSString *key = [ thing performSelector: selectorIn ]; Not that it matters here - these lines will be executed a few dozen times. But I just want to know. Kind regards, Gerriet. _______________________________________________ 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 arch...@mail-archive.com