Note that there are some explanatory texts on larger screens.

plurals
  1. PO'isMemberOfClass' returning 'NO' when custom init
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11675256/ismemberofclass-returns-no-when-viewcontroller-is-instantiated-from-uistoryboard">isMemberOfClass returns no when ViewController is instantiated from UIStoryboard</a> </p> </blockquote> <p>I recently stumbled over a weird problem:</p> <p>I was implementing simple Testcases and using the NSObject isMemberOfClass method to check for class equality.</p> <p>Additionally I implemented a custom init:</p> <pre><code>-(id)initWithMessage:(NSString *)message </code></pre> <p>If I replace id with the right class name the isMemberOfClass will return 'YES'. Otherwise it will fail.</p> <p>The interesting part is: The class Method will return the right Class every time.</p> <p>Is this a bug? Or is it supposed to work that way?</p> <p>Thanks..</p> <p>EDIT:</p> <p>Ok this did not solve the problem.. Here is what I do.. isMemberOfClass will always return NO</p> <p>Testcase:</p> <pre><code>- (void)test010_broadcastWait {    ...    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData                                                           options:0 error:&amp;error];    Brick *newBrick = [self.parser loadBroadcastWaitBrick:doc.rootElement];    if (![newBrick isMemberOfClass:[BroadcastWaitBrick class]])        STFail(@"Wrong class-member");    .... } </code></pre> <p>BroadCastWait Class:</p> <p>import "BroadcastWaitBrick.h"</p> <pre><code>@implementation BroadcastWaitBrick -(id)initWithMessage:(NSString *)message { self = [super init]; if (self) { self.message = message; } return self; } ... </code></pre> <p>loadMethod:</p> <pre><code>-(BroadcastWaitBrick*)loadBroadcastWaitBrick:(GDataXMLElement*)gDataXMLElement { NSArray *messages = [gDataXMLElement elementsForName:@"broadcastMessage"]; GDataXMLElement *message = (GDataXMLElement*)[messages objectAtIndex:0]; BroadcastWaitBrick* brick = [[BroadcastWaitBrick alloc]initWithMessage:message.stringValue]; return brick; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload