Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C Types as parameter

Tags:

objective-c

Okay I am not asking HOW to get a parameter when calling a method or something.

I want something like this:

-(void)doSomethingWithType:(TYPE)type {

//do something

}

and executed like this:

[self doSomethingWithType:int];

or

[self doSomethingWithType:BOOL];

How can I make a parameter of a method/function that has a type as parameter? I mean any type.. :)

I dont want to make a int parameter, I want to make a int-type parameter, where you write the objective c type as parameter and not a value or variable :)

Thanks!

like image 428
Janosch Hübner Avatar asked Dec 09 '22 14:12

Janosch Hübner


1 Answers

I'm not sure if I understand your intention correctly, but Objective-C has a class "Class".

-(void)doSomethingWithType:(Class)type {
    //do something
    //for example, create an instance of this type:
    id object = [[type alloc] init];
}

And you can call it like so:

[objectOfMyClass doSomethingWithType: [SomeObjectiveCType class]];

It won't work with primitive types though. I mean BOOL, int, float, etc. Objective-C classes only. Hope, that it will help. Sorry if that's not what you're looking for.

like image 154
FreeNickname Avatar answered Mar 19 '23 03:03

FreeNickname