I received a return value from SQLite fetch
int primaryKey = sqlite3_column_int(statement, 0);
and I'm going to use it as a selector's object:
[[ABC alloc] performSelector:@selector(abcWithAAA:) withObject:[NSNumber numberWithInt:primaryKey]];
the NSLog result for primarykey is a number 4:
NSLog(@"primaryKey:%i",primaryKey);
4
but the NSLog result for [NSNumber numberWithInt:primaryKey] is 131628896.
why? and how do i convert the int value correctly?
Thanks!
Best Answer
I solved the problem using an adapter method that does the cast for the withObject method. My problem was that I wanted to use a typedef enum and pass it as value to the withObject.
I wanted to call this method using the performSelect message:
As you see it request a MonsterTypes typedef defined like this:
Actually to be able to call the method above I build this adapter that calls it then:
It is used this way:
You can find it explained in more detail here: http://kerkermeister.net/objective-c-adapter-from-nsinteger-to-id-when-using-performselector-withobject/