Objective-C Custom extend

Posted by ryanjm.mp on Stack Overflow See other posts from Stack Overflow or by ryanjm.mp
Published on 2010-06-07T21:49:47Z Indexed on 2010/06/07 21:52 UTC
Read the original article Hit count: 275

Filed under:
|
|

I have a couple classes that have nearly identical code. Only a string or two is different between them. What I would like to do is to make them from another class that defines those functions and then uses constants or something else to define those strings that are different. I'm not sure if "___" is inheritance or extending or what. That is what I need help with.

For example:

objectA.m:

-(void)helloWorld {
    NSLog("Hello %@",child.name);
}

objectBob.m:

#define name @"Bob"

objectJoe.m

#define name @"Joe"

(I'm not sure if it's legal to define strings, but this gets the point across)

It would be ideal if objectBob.m and objectJoe.m didn't have to even define the methods, just their relationship to objectA.m. Is there any way to do something like this?


If all else fails I'll just make objectA.m:

-(void)helloWorld:(NSString *name) {
    NSLog("Hello %@",name);
}

And have the other files call that function (and just #import objectA.m).

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about inheritance