Note that there are some explanatory texts on larger screens.

plurals
  1. POisMemberOfClass doesn't work as expected with ocunit
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/12692854/ismemberofclass-returning-no-when-custom-init">&#39;isMemberOfClass&#39; returning &#39;NO&#39; when custom init</a> </p> </blockquote> <p>I've some trouble with the "isMemberOfClass"-Method.</p> <p>I have a class, that generates and returns objects ("<code>MyObject</code>")</p> <pre><code>// ObjectFactory.h ... -(MyObject*)generateMyObject; ... // ObjectFactory.m ... -(MyObject*)generateMyObject { MyObject *obj = [[MyObject alloc]init]; obj.name = @"Whatever"; // set properties of object return obj; } ... </code></pre> <p>And there's a unittest-class, that calls the <code>generateMyObject</code>-selector and checks the class of the returned object:</p> <pre><code>... ObjectFactory *factory = [[ObjectFactory alloc]init]; MyObject *obj = [factory generateMyObject]; if (![obj isMemeberOfclass:[MyObject class]]) STFail(@"Upps, object of wrong class returned..."); else ... </code></pre> <p>I expect, that the <code>else</code>-part is processed...but the STFail(...) is called instead, but why?</p> <p>Thx for any help! Regards, matrau</p> <p>Ok, here is the original copy&amp;pasted code:</p> <pre><code>//testcase - (void)test001_setCostumeFirstCostume { NSString *xmlString = @"&lt;Bricks.SetCostumeBrick&gt;&lt;costumeData reference=\"../../../../../costumeDataList/Common.CostumeData\"/&gt;&lt;sprite reference=\"../../../../..\"/&gt;&lt;/Bricks.SetCostumeBrick&gt;"; NSError *error; NSData *xmlData = [xmlString dataUsingEncoding:NSASCIIStringEncoding]; GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&amp;error]; SetCostumeBrick *newBrick = [self.parser loadSetCostumeBrick:doc.rootElement]; if (![newBrick isMemberOfClass:[SetCostumeBrick class]]) STFail(@"Wrong class-member"); } // "MyObject" @implementation SetCostumeBrick @synthesize indexOfCostumeInArray = _indexOfCostumeInArray; - (void)performOnSprite:(Sprite *)sprite fromScript:(Script*)script { NSLog(@"Performing: %@", self.description); [sprite performSelectorOnMainThread:@selector(changeCostume:) withObject:self.indexOfCostumeInArray waitUntilDone:true]; } - (NSString*)description { return [NSString stringWithFormat:@"SetCostumeBrick (CostumeIndex: %d)", self.indexOfCostumeInArray.intValue]; } @end // superclass of SetCostumeBrick @implementation Brick - (NSString*)description { return @"Brick (NO SPECIFIC DESCRIPTION GIVEN! OVERRIDE THE DESCRIPTION METHOD!"; } //abstract method (!!!) - (void)performOnSprite:(Sprite *)sprite fromScript:(Script*)script { @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] userInfo:nil]; } @end // the "factory" (a xml-parser) - (SetCostumeBrick*)loadSetCostumeBrick:(GDataXMLElement*)gDataSetCostumeBrick { SetCostumeBrick *ret = [[SetCostumeBrick alloc] init]; NSArray *references = [gDataSetCostumeBrick elementsForName:@"costumeData"]; GDataXMLNode *temp = [(GDataXMLElement*)[references objectAtIndex:0]attributeForName:@"reference"]; NSString *referencePath = temp.stringValue; if ([referencePath length] &gt; 2) { if([referencePath hasSuffix:@"]"]) //index found { NSString *indexString = [referencePath substringWithRange:NSMakeRange([referencePath length]-2, 1)]; ret.indexOfCostumeInArray = [NSNumber numberWithInt:indexString.intValue-1]; } else { ret.indexOfCostumeInArray = [NSNumber numberWithInt:0]; } } else { ret.indexOfCostumeInArray = nil; @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"Parser error! (#1)"] userInfo:nil]; } NSLog(@"Index: %@, Reference: %@", ret.indexOfCostumeInArray, [references objectAtIndex:0]); return ret; } </code></pre> <p>SOLUTION: </p> <p>Eiko/jrturton gave me a link to the solution - thx: <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> <p>The problem was, that the classes were included in both targets (app and test bundle)</p> <p>Thank you guys for your help :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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