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

  • Home
  • SEARCH
  • 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 8393969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:56:37+00:00 2026-06-09T19:56:37+00:00

I have added several class Objects into a NSMutableArray . It seems to have

  • 0

I have added several class Objects into a NSMutableArray. It seems to have worked however I would like to now access the variables that are inside the class object I have stored into the array, however I am now running into some errors.

Initially I have a NSDictionary of entries that are all NSString based the purpose of the method I am passing this NSArray of NSDictionary/s too is to take each entry in the dictionary and place it into a variable of the correct type. Then this NSObject of variables is passed back to where it was called from.

Below is the code I am using to achieve this.

response.m

 // initalise NSOject Class
  SearchResultList *searchResultList = [[SearchResultList alloc]init];

 // Create mutableArray with compacity (compacity is based of the current array of NSDictionarys (entries are strings))
   NSMutableArray *searchObjectArray = [[NSMutableArray alloc] initWithCapacity:[filteredArray count]];

  // count to track progress of the array
   int myCount = 0;

  // for loop goes through the array passing each object in the array over to the search class object
   for (id obj in filteredArray) {

        // Pass current array object over to the NSObject Class Method, this method assigns the entires of the NSDictionary object to the variables of the object class coorect type values
          [searchResultList assignSearchData:filteredArray[myCount]];

         // This is where I capture the returning NSObject Class (at least I think thats whats happening.
           [searchObjectArray addObject:searchResultList];

         // increments count
            myCount ++;

    }

//..

This is the class method that being called inside the for loop

SearchResultList.m

//return is of type, SearchResultList which is the object class itself... not sure if this is 100% correct.
- (SearchResultList *)assignSeriesSearchData:(NSMutableDictionary*)tempDict
{

//add all of the NSDictionary entries into their own variables of the correct type such as

// initalize DOORID - NSInteger
    doorID = [[tempDict valueForKey:@"DOORID"] integerValue];

// initalize DOORDESC - NSString
    doorDesc = [tempDict valueForKey:@"DOORDESC"];

// initalize DOOROPEN - BOOL
    doorOpen = [[tempDict valueForKey:@"DOOROPEN"] boolValue];

 // initalize DOORLETTER - char
    doorLetter = [[tempDict valueForKey:@"DOORLETTER"] UTF8String];

//...

//then I return the NSObject Class to the place where it was called

return self;
}

So from here, I end up back in the for Loop of response.m where I call searchObjectArray addObject:searchResultList]; to capture the the returning class object.

At this point I have two questions.

First, am I capturing the the NSObject Class correctly

Second, Once I have added all of the Class Objects to the array how could I then acces the variables of a specific object in the array?

The reason I ask the second question Is because I am wanting to pass this array to a sorting method, which sorts based off one or more variables of the objects that are in the array.

Any help would be greatly appreciated.

  • 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-06-09T19:56:39+00:00Added an answer on June 9, 2026 at 7:56 pm

    To your first question: you should alloc/init a new instance of your SearchResultList class within your loop, otherwise you will just be reusing and overwriting the same object. In your question you keep referring to is as an NSObject, which it technically is, being a subclass of NSObject, but it is really an instance of your custom class. (As a side note I would suggest using a class name like SearchResultItem instead rather than SearchResultList, since it is not really a list and this could be confusing to someone looking at your code, but I’ve left it the way you had it.)

    NSMutableArray *searchObjectArray = [[NSMutableArray alloc] initWithCapacity:[filteredArray count]];
    
    for (NSDictionary *obj in filteredArray) {
        SearchResultList *searchResultList = [[SearchResultList alloc] init];
        [searchResultList assignSearchData:obj];
        [searchObjectArray addObject:searchResultList];
    }
    

    Also note that since you are using fast iteration for your loop you don’t need your myCount counter, since fast iteration pulls out the next object in your array for you to use with each iteration of the loop.

    For your second question, you need to first cast the objects coming out of your array as your custom class (SearchResultList) in order to access the specific property. For example:

    SearchResultList* myObj = (SearchResultList*)[searchObjectArray objectAtIndex:0];
    int doorID = myObj.doorID;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class Person. Several Person objects have been created and added
I have several Core Data model version that I have added to my .xcdatamodeld
I have several forms added to the pages of the tab control via tabcontrol.tabpages.controls.add
I have several ReorderLists on a page. Each list has items added to it
I have a form in which several buttons are added at runtime via a
I have to serialize several objects inheriting from WebControl for database storage. These include
If I have a list of elements I would like to sort, Java offers
I have a class A maintaining a list of objects class B. But each
I have a vector of class objects I've created in main by reading in
I'd like to have several fields in my form being rendered as ChoiceFields which

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.