Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble Accessing Custom-Object Property in NSMutableArray
    text
    copied!<p>I'm in some kind of structuring trouble here because I'm not sure if what I'm trying to do is possible:</p> <p>I have three custom classes that represent types of instructions translated from machine code. Each class has properties like the function of the instruction and the operands. They get initialised and translated into instances in the third VC and put in an NSMutableArray and I successfully move that NSMutableArray to the fourth VC. Now, I need to loop through each object of the array (not knowing which type of class it is) and access the "instruction" property of it (an NSString, that is). Is that possible?</p> <p>Declaration example of one of the classes:</p> <pre><code>@interface iInstruction : NSObject @property (strong) NSString *opCode; @property (strong) NSString *rs; @property (strong) NSString *rt; @property (strong) NSString *immediate; @property (strong) NSMutableString *instruction; - (id) initWithBinary: (NSString *) binaryInstruction; </code></pre> <p>How the instance is created and moved to fourth VC:</p> <pre><code>iInstruction *NewI = [[iInstruction alloc] initWithBinary:binary32Bits]; [TranslatedCode appendFormat:@"%@\n", NewI.instruction]; [instructions addObject: NewI]; disassembledCode.text = TranslatedCode; FourthViewController *theVCMover = [self.tabBarController.viewControllers objectAtIndex:3]; theVCMover.instructionsInfo = instructions; </code></pre> <p>A failed attempt of what I'm trying to do:</p> <pre><code>for (NSUInteger i=0; i &lt; [instructionsInfo count]; i++) { //instructionsInfo is a property of the fourth VC that I use to move the main array from the third VC NSString *function = [instructionsInfo objectAtIndex:i].instruction; //Of course it says property not found because it only receives the NSMutableArray at runtime if (function isEqualToString:@"andi") { } </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