New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
iOS and Apps All your questions and discussion of iOS or iOS Apps.

Help with Obj C - creating multiple objects


Post Reply New Thread Subscribe

 
Thread Tools
capturenow

 
Member Since: Sep 22, 2011
Posts: 2
capturenow is on a distinguished road

capturenow is offline
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.
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,109
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
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; 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 Debian as a server; Apple TV (1080p version)
QUOTE Thanks
capturenow

 
Member Since: Sep 22, 2011
Posts: 2
capturenow is on a distinguished road

capturenow is offline
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.
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,109
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
No worries, just kinda funny sometimes

My Macs: Late 2013 rMBP w/ 750m; 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 Debian as a server; Apple TV (1080p version)
QUOTE Thanks

Post Reply New Thread Subscribe


« iOS upgrade help | good app »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Time Machine never finishes? rsales Other Hardware and Peripherals 8 01-26-2011 05:45 PM
Multiple displays in virtual box NyoGoat Running Windows (or anything else) on your Mac 0 04-07-2010 05:48 PM
creating a continuous play cd-r with multiple tracks marin_kids_club Music, Audio, and Podcasting 1 12-07-2007 10:39 AM
Creating shared objects (dylibs) xwasp OS X - Development and Darwin 3 10-01-2006 11:31 AM
Upgrading PERL Forum Setup, MySQL, etc. ssotti OS X - Development and Darwin 0 11-29-2003 11:16 AM

All times are GMT -4. The time now is 09:00 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?