Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess an NSMutableArray of objects which are in another NSMutableArray (I.E. Nested Object access)
    primarykey
    data
    text
    <p>I have a class (USER) which has the following properties (NSString name, NSString address, NSMutableArray tags). The tags property is an NSMutableArray of (TAG) - TAG is a class defined as (NSNumber tagId, NSString tagName).</p> <p>I have tried a few different ways to access the tagName and tagId however have been unsuccessful. </p> <p>Example code 1 below:</p> <pre><code>Tag *tag = [[Tag alloc] init]; for(NSInteger n = 0; n &lt; [thisSpotTag count]; n++) { NSLog(@"%@", [thisSpotTag objectAtIndex:n]); } </code></pre> <p>Example code 2 below:</p> <pre><code>NSEnumerator *enumerator = [thisSpotTag objectEnumerator]; NSString *tname = nil; while((tname = [enumerator nextObject])) { NSLog(@"%@", tname); } </code></pre> <p>In both examples, I get the memory address of the tag, but not the value of the tagName and tagId. </p> <p>How do I access this information?</p> <p>PS - I am using xCode 4.2 with ARC.</p> <hr> <p>Update on my question below:</p> <p>I'm back, and tried a few of the suggested fixes below however I still cannot get the data out of the array. Remember, I have an array of objects in which each object contains an array of objects.</p> <p>I have this code for example:</p> <pre><code>NSEnumerator *enumerator = [thisUser.tags objectEnumerator]; Tag *tagObj = [[Tag alloc] init]; while(tagObj = [enumerator nextObject]) { NSLog(@"enumerated tag id:%@ name:%@", tagObj.tid, tagObj.name); } </code></pre> <p>I never make it into the while loop in the code above...</p> <p>thisUser.tag is the TAG object for portion of a USER object. Perhaps typing out what the array looks like would help explain the nesting. </p> <pre><code>NSMutableArray( "this is an NSMutableArray of USER objects" element 0 =&gt; USER Object 1 USER.name is an NSString USER.address is an NSString USER.tag "this is an NSMutableArray of TAG objects" element 0 =&gt; TAG Object 1 TAG.tagId is an NSNumber TAG.tagName is an NSString element 1 =&gt; TAG Object 2 ...etc... element 1 =&gt; USER Object 2 ...etc... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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