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 8186095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:04:35+00:00 2026-06-07T02:04:35+00:00

Best related discussions I’ve turned up: Making an array of Objects in Objective-C. .

  • 0

Best related discussions I’ve turned up: Making an array of Objects in Objective-C.. Scanned through links that came up when I prepped this post.

Self-study mode, creating mini-apps to reinforce and extend ideas I get working on book tutorials.
…………….

Goal: To store some number of objects (example class ‘Trip’) in a mutable array, contained in another object (example class ‘TourCompany’).

(portions of the two different class interface files)

    @interface Trip : NSObject
    @property (strong, nonatomic) NSString *travelToLocation;

……

        @interface TourCompany : NSObject
        @property (strong, nonatomic) NSMutableArray *trips ;

…… CODE AND GOAL IN PIECES….

1) Demonstrate that I created 3 trip objects and can access the travelToLocation ivar
….

        Trip *trip0 = [[Trip alloc] init];
        Trip *trip1 = [[Trip alloc] init];
        Trip *trip2 = [[Trip alloc] init];

        [trip0 setTravelToLocation:@"Vienna"];
        [trip1 setTravelToLocation:@"Mt. St. Helens"];
        [trip2 setTravelToLocation:@"Tenochtitlan"];

        NSString *somePlace1 = trip1.travelToLocation;

        NSLog(@" %@ %@, \n \t Let's LOOK at one particular trip ivar %@.", twoBlanks, nuLn, somePlace1);

     //  CONSOLE RESULTS
      //     Let's LOOK at one particular trip ivar Mt. St. Helens.

….
2) Demonstrate that I
i) can store these 3 trip objects in a locally declared NSMutable Array
ii) can access the travelToLocation ivar
….

     // put trip objects into a LOCALLY DECLARED mutable array
        NSMutableArray *localTripsArray = [NSMutableArray array ];

      //[myArray addObject: someOtherPerson]; - compare to a STackOverflow discussion

        [localTripsArray addObject:trip0];
     [localTripsArray addObject:trip1];
        [localTripsArray addObject:trip2];


        for (Trip *t in localTripsArray) {

            NSLog(@"\n \t ^^^Trip location in LOCAL TRIPS Mutable ARRAY is %@", t.travelToLocation );

     }



    /*
        CONSOLE RESULTS
     objectInMutableArrayMiniAppChallenge[521:f803] 
        ^^^Trip location in LOCAL TRIPS Mutable ARRAY is Vienna
2012-07-05 13:47:17.172 objectInMutableArrayMiniAppChallenge[521:f803] 
        ^^^Trip location in LOCAL TRIPS Mutable ARRAY is Mt. St. Helens
        2012-07-05 13:47:17.172 objectInMutableArrayMiniAppChallenge[521:f803] 
         ^^^Trip location in LOCAL TRIPS Mutable ARRAY is Tenochtitlan

        */

….
3) BUT I cannot figure out why I am not storing these 3 objects an NSMutable Array (‘trips’) in an instance of my TourCompany class (‘friendlySkiesTourCo’)
…
// NOW instantiate an object in my TourCompany class

    TourCompany *friendlySkiesTourCo = [[TourCompany alloc] init];

 // put those same objects into the trips ivar in that object
 //[myArray addObject: someOtherPerson]; 
    //     - compare to a STackOverflow discussion
    //only difference I see is that instead of locally declared 'myArray'
    //   I'm using an ivar that's a member of an object
 // I know there's are values in those objects, because I displayed them above


 [friendlySkiesTourCo.trips addObject:trip0];
    [friendlySkiesTourCo.trips addObject:trip1];
    [friendlySkiesTourCo.trips addObject:trip2];


    for (Trip *t in friendlySkiesTourCo.trips) {

NSLog(@”\n \t +++ Trip location in ‘trips’ mutable array in the object ‘friendlySkiesTourCo’, a TourCompany class object, is %@”, t.travelToLocation );

    }


    /* Console NON-Results

    I never get any output from this NSLog directive
     I'll bet there is something pretty basic I don't understand
     No doubt, it's in the Gol Durned Manual online , but I'm not seeing it
     */

….
4. Let’s just double check that the problem is possibly a setting type problem
….
// I don’t think I’m really putting the objects into this particular mutable array in the friendlySkies object correctly
// Let’s just check

 int howManyTripsInMutableArray = [friendlySkiesTourCo.trips count];

 NSLog(@"\n \tThere are %d trips for the friendlySkiesTour Co ", howManyTripsInMutableArray);

        /*

     Sure enough...

     2012-07-05 13:53:53.235 objectInMutableArrayMiniAppChallenge[555:f803] 
    There are 0 trips for the friendlySkiesTour Co 

    */

Thanks for any clues. I hope that I did this writeup succinctly and that you don’t think I just didn’t RTGDM (that’s ‘gol durn’ in case you wondered), because I sure tried to.

Laurel

  • 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-07T02:04:38+00:00Added an answer on June 7, 2026 at 2:04 am

    I’m willing to bet you didn’t initialize friendlySkiesTourCo.trips. ie

    friendlySkiesTourCo.trips = [[NSMutableArray alloc] init];
    

    EDIT

    As @Chuck pointed out below in the comments, this allocation should really be done in the initializer method for the class:

    @implementation TourCompany
    
    -(id) init
    {
        self = [super init];
    
        self.trips = [[NSMutableArray alloc] init];
    
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this related question: Deep cloning objects Is this really the best way to
This question is related to this one: Best way to store product colors in
What are the best practices to define - in Play Framework - objects that
This question is only related to the first parameter in any event handler, that
What's the best way to extract the related data from a has many through
Is there a common method/best practice/any means for combining forms that span multiple related
My question is related to this other discussion . I'm trying to implement that
There is a related question to this: What's the best method to pass parameters
This question is not related to: Best way to break long strings in C#
This question is in a sense related to Best way to share common code

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.