Typecasting doesn't work. How to convert an object?
Posted
by Nastase Ion
on Stack Overflow
See other posts from Stack Overflow
or by Nastase Ion
Published on 2010-05-01T17:21:40Z
Indexed on
2010/05/01
17:27 UTC
Read the original article
Hit count: 135
objective-c
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??
© Stack Overflow or respective owner