Storing Object Types in Variable then Initializing

Posted by Jon Mattingly on Stack Overflow See other posts from Stack Overflow or by Jon Mattingly
Published on 2012-07-10T20:51:50Z Indexed on 2012/07/10 21:15 UTC
Read the original article Hit count: 210

Filed under:
|
|
|

Is there a way in Objective-C to store an object/class in a variable to be passed to alloc/init somewhere else?

For example:

UIViewController = foo
foo *bar = [[foo alloc] init]

I'm trying to create a system to dynamically create navigation buttons in a separate class based on the current view controller. I can pass 'self' to the method, but the variable that results does not allow me to alloc/init. I could always import the .h file directly, but ideally I would like to make reusing the code as simple as possible. Maybe I'm going about this the wrong way?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about class