0 Replies - 2914 Views - Last Post: 07 May 2013 - 11:07 AM

#1 lifeinbinary  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 160
  • Joined: 15-February 11

Function passing (obj-c)

Posted 07 May 2013 - 11:07 AM

Although this is not directly about gaming, I'm building a game so here it is:

I need to pass a function from one class to another. I figure using @selector is the way to go but I don't understand it completely I guess.

Let's say I have a class (this is not really the classes but it's a good example):

@interface AlphabetClass : NSObject


// All letters have  a func

@property (retain,nonatomic) NSMutableArray *letterSprites;



@implementation AlphabetClass


// Fill letterSprites array



// Do something


// Rest of funcs here... funcB, funcC...

So now I need to pass an instance of this class to a LetterFactory class that will produce instances of a Letter class that will hold the sprite for it's appropriate letter and the function for that letter. My problem is passing the function from the Alphabet class to the Letter class. I know it has to do with SEL and targets but I don't want the Letter class to need to point to the Alphabet class to get the function. How can I pass the function so that the letter class need not look anywhere but in itself to use it's given func?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1