Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7023609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:43:58+00:00 2026-05-27T23:43:58+00:00

I have a class (USER) which has the following properties (NSString name, NSString address,

  • 0

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).

I have tried a few different ways to access the tagName and tagId however have been unsuccessful.

Example code 1 below:

Tag *tag = [[Tag alloc] init];
for(NSInteger n = 0; n < [thisSpotTag count]; n++)
{
    NSLog(@"%@", [thisSpotTag objectAtIndex:n]);
}

Example code 2 below:

NSEnumerator *enumerator = [thisSpotTag objectEnumerator];
NSString *tname = nil;
while((tname = [enumerator nextObject]))
{
    NSLog(@"%@", tname);
}

In both examples, I get the memory address of the tag, but not the value of the tagName and tagId.

How do I access this information?

PS – I am using xCode 4.2 with ARC.


Update on my question below:

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.

I have this code for example:

NSEnumerator *enumerator = [thisUser.tags objectEnumerator];
Tag *tagObj = [[Tag alloc] init];    
while(tagObj = [enumerator nextObject])
{
    NSLog(@"enumerated tag id:%@ name:%@", tagObj.tid, tagObj.name);
}

I never make it into the while loop in the code above…

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.

NSMutableArray(               "this is an NSMutableArray of USER objects"
    element 0 =>  USER Object 1
        USER.name is an NSString
        USER.address is an NSString
        USER.tag              "this is an NSMutableArray of TAG objects"
            element 0 => TAG Object 1
                TAG.tagId is an NSNumber
                TAG.tagName is an NSString
            element 1 => TAG Object 2
               ...etc...
    element 1 => USER Object 2
        ...etc...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:43:58+00:00Added an answer on May 27, 2026 at 11:43 pm

    Try casting then accessing the properties:

    [(Tag *)[array objectAtIndex:i] tagId];
    [(Tag *)[array objectAtIndex:i] tagName];
    

    Or, for fast enumeration (better), do

    (Tag *)tag = [enumerator nextObject];
    tag.tagId;
    tag.tagName;
    

    For an NSMutableArray of Users, you need to cast like this:

    User *user = (User *)[array objectAtIndex:i];
    Tag *tag = (Tag *)[user.tags objectAtIndex:j];
    

    Now you can simply call properties:

    tag.tagId;
    tag.tagName;
    

    Remember that whenever you are using an NSMutableArray or NSArray with custom objects, all you need to do is to tell the compiler what type the object is. Then everything will work as you expect.

    Here’s an example for your case, starting with NSMutableArray *usersArray of Users:

    for (int i=0; i<usersArray.count; ++i) {
        User *user = (User *)[usersArray objectAtIndex:i];
        NSLog(@"Name: %@\n",user.name);
        NSLog(@"Address: %@\n",user.address);
        NSLog(@"Tags: \n");
        for (int j=0; j<[user.tags count]; ++j) {
            NSLog(@"ID: %@", (Tag *)[[user.tags objectAtIndex:j] tagID]);
            NSLog(@"Name: %@", (Tag *)[[user.tags objectAtIndex:j] tagName]);
        }
        [user release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application I have a class which has properties of user-defined types like
I have a class named InvoiceLine which has the following properties. public class InvoiceLine
I have a UserPass class which has 2 properties: User user; String password User
I have the following class which handles my user logged in / logged out
I have some logic, which defines and uses some user-defined types, like these: class
Lets say I have object Tom which has class Person. Class Person String Name
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have the following @OneToOne relation: @Entity @Table(name=USER) public class User implements Serializable{ private
I have db.Model which has several properties as described below: class Doc(db.Model): docTitle =
I have a user control which implements INotifyPropertyChanged and has a property SelectedTopicDescription and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.