• 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: Calling a method based on a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling a method based on a string


  • Subject: Re: Calling a method based on a string
  • From: Jacob Lukas <email@hidden>
  • Date: Sun, 10 Oct 2004 21:48:17 -0700


On Oct 10, 2004, at 9:42 PM, Lee Morgan wrote:

I've looked though tons of docs and tried my best to search the archives for this; but I just can't find a answer....
Is it possible to call a method at runtime when all my app knows is a string of the method?
For example object A has a string called "drawRect" and a rectangle called myDrawRect
Then I want object B to perform drawRect with myDrawRect as it's parameter.
So it would be something like [objectB doMethod:@"drawRect" withParameter:myDrawRect];

[objectB performSelector:NSSelectorFromString(@"drawRect") withObject:myDrawRect];

of course it's better to do this:

[objectB drawRect:myDrawRect];

Jacob


<x-tad-smaller>PowerMac G4 Digital Audio 466MHz, ATI Radeon 9000 128MB VRAM, 896MB RAM, Mac OS 10.3.5... yes I know, it's time to get a new computer
</x-tad-smaller>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Calling a method based on a string
      • From: "Louis C. Sacha" <email@hidden>
    • Re: Calling a method based on a string
      • From: Fritz Anderson <email@hidden>
References: 
 >Calling a method based on a string (From: Lee Morgan <email@hidden>)

  • Prev by Date: Calling a method based on a string
  • Next by Date: Re: Getting objectSpecifier right...
  • Previous by thread: Calling a method based on a string
  • Next by thread: Re: Calling a method based on a string
  • Index(es):
    • Date
    • Thread