Typecasting doesn't work. How to convert an object?
- by Nastase Ion
Hi everyone!
I need to convert a custom object to a different object. How can I do that?
I know that typecasting doesn't work (the only thing is does is "shuts the compiler warnings off", but nothing more). Here is a sample code:
MyType* obj1;
MyOtherType* obj2;
obj1 = [MyType initWithData: 1];
obj2 = (MyOtherType*) obj1;
if ([obj2 isMemberOfClass: [MyOtherType class]]) { NSLog(@"OK"); }
else if ([obj2 isMemberOfClass: [MyType class]]) { NSLog(@"Nope"); }
The result is:
Nope
What can I do??