Results 1 to 4 of 4
  1. #1


    Member Since
    Sep 22, 2011
    Posts
    2
    Help with Obj C - creating multiple objects
    As newbie, Im stuck on getting the values from objects I have put in a NSMutableArray. To give a full picture of my problem I would appreciate you reading the following:

    So lets say I produce a new object as follows (writing to console):

    Person *player = [[Person alloc] init];

    player.age = 10;
    player.height = 10;
    player.name = @"player";

    As I continue to write my programme I can change the above values of player (not at run time) i.e

    player.age = 23; etc.....

    If I want to create another Person (player2) I repeat the above like this:

    Person *player1 = [[Person alloc] init];

    player1.age = 13;
    player1.height = 4;
    player1.name = @"player1";

    In my programme I can now change and compare values of the 2 objects i.e.

    if (player.age == player1.age) bla bla bla

    My problem starts if I want to create 20+ Person objects - I know how to place all the objects in a loop/NSMutableArray as follows:

    for (int i = 0; i < 20; i++)

    { Person *player = [[Person alloc] init];

    player.age = 10;
    player.height = 10;
    player.name = @"player";
    [myArray addObjectlayer];
    [player release];
    }

    All the objects in myArray are individual but have the same values. Thats fine ! But how to get or change the objects in myArray ? (not at run time)

    If [myArray objectAtIndex:4]; holds the following values:

    player.age = 10;
    player.height = 10;
    player.name = @"player";

    how do I get to the object(s) in myArray so I can compare/sort/add etc..

    Heres example of what I want to do but I know is wrong:

    if (player.age == [myArray personAtIndex:15.age]; // wrong !

    or

    NSLog(@"@ has a height of %i",[myArray personAtIndex:15:name:height];

    prints out >> person has a height of 10

    I really would appreciate you helping me on this - As a newbie I'm finding it hard to move on until I get an understanding of this problem. Thanks again.

  2. #2


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    Why does this post look awful similar (to near about identical) to the one I replied to that was on TNB ( TheNewBoston Forum &bull; View topic - values from multiple objects in NSMutableArray (console) )

    That said, there is a developer topic on this forum that you can find at the bottom of the topic list.
    My Macs: Late 2013 rMBP w/ 750m, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Linux; Apple TV (1080p version)

  3. #3


    Member Since
    Sep 22, 2011
    Posts
    2
    Hi Nethfel
    Yes that was me being rather impatient and desperate last night for an answer.
    When I wrote this post I hadnt realised that you had sent a 2nd answer on the newNoston forum that really solved my query.

    I have replied to you at newBoston and again, thank you for all your help.

  4. #4


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    No worries, just kinda funny sometimes
    My Macs: Late 2013 rMBP w/ 750m, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Linux; Apple TV (1080p version)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating A Bootable Backup Of Drive With Multiple Volumes
    By PGB1 in forum OS X - Operating System
    Replies: 5
    Last Post: 10-09-2014, 06:46 PM
  2. Creating multiple choice tests
    By Kyle12 in forum Switcher Hangout
    Replies: 2
    Last Post: 12-10-2012, 10:59 PM
  3. multiple objects
    By necromalice in forum iOS Development
    Replies: 3
    Last Post: 09-23-2011, 01:33 PM
  4. creating a continuous play cd-r with multiple tracks
    By marin_kids_club in forum Music, Audio, and Podcasting
    Replies: 1
    Last Post: 12-07-2007, 10:39 AM
  5. Creating shared objects (dylibs)
    By xwasp in forum OS X - Development and Darwin
    Replies: 3
    Last Post: 10-01-2006, 11:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •