Reputation: 1327
i want to convert id* to NSNumber *
trying this
unsigned int ShortValue = [(NSNumber *)idObject unsignedShortValue];
but this aint compiling
Cast of an indirect pointer to an Objective-C pointer to 'NSNumber *' is disallowed with ARC
any ideas how to do it. basically id* object will be argument to my method ,second argument will be type information of this id* object then inside this method i am performing type specific methods on it like one above
Upvotes: 0
Views: 2542
Reputation: 11595
id
is a semi-primitive type, as it is declared in objc.h as
typedef struct objc_object {
Class isa;
} *id;
When you create id objects, you don't use an "*", as that is for pointers to objects, so basically don't do this:
id *someObject;
The correct syntax would be this:
id someObject;
Hope this helps!
--------EDIT------ I tried out the code you used:
unsigned int ShortValue = [(NSNumber *)idObject unsignedShortValue];
and it compiled fine. I think the error is how you create idObject
.
---------EDIT---------
Here's an apple doc on id
: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocObjectsClasses.html
and here's two good resources on the isa
pointer: What does isa mean in objective-c?, http://cocoasamurai.blogspot.com/2010/01/understanding-objective-c-runtime.html. In the second link, scroll to the top third of the article to find info on isa*
. Hope this helps!
Upvotes: 1