• 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: Arc and performSelector
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arc and performSelector


  • Subject: Re: Arc and performSelector
  • From: glenn andreas <email@hidden>
  • Date: Mon, 17 Oct 2011 12:29:50 -0500

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];
}


Glenn Andreas                      email@hidden
The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL

_______________________________________________

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: Arc and performSelector
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >Arc and performSelector (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Is it possible to use Radio Group(NSMatrix) in a different way?
  • Next by Date: Re: Arc and performSelector
  • Previous by thread: Re: Arc and performSelector
  • Next by thread: Re: Arc and performSelector
  • Index(es):
    • Date
    • Thread