Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-22-2011, 02:45 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 1
capturenow is on a distinguished road
Default getting values after 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:

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.
capturenow is offline   Reply With Quote
Old 09-23-2011, 11:59 PM   #2 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

I dont have a ton of cocoa experience, but I would imagine that you could do something like this:
Code:
if (player.age == [myArray objectAtIndex:15].age){}

but you might have to do it like this:

Person *compairPerson = [myArray objectAtIndex:15];
if(player.age == compairPerson.age){
// do stuff
}
__________________
Sir Charles Barkley
newDev is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On



» Advertisements
» Online Users: 471
13 members and 458 guests
AlanFloyd, AppsBlogger, David-T, HemiMG, iAppDeveloper, imac74, Jaxen66, lovoyl, mutantskin, Paul Slocum, tiendung2992, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,684
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, tiendung2992
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0