After 10 years without programming (in Delphi at the time), I began learning Objective-C. I confess I have met lots of problems as this approach is very different.
I want to make a simple table in which each line consists of several NSString variables. An example:
ID Firstname Lastname
01 FN1 LN1
02 FN2 LN2
My table:
NSString * FirstName, * LastName;
NSMutableArray * person = [NSMutableArray arrayWithObjects: firtsname, lastname, nil];
The problem is that I can not add a line with the 2 NSString, for example:
FirstName = @ "FN1";
LastName = @ "LN1";
[person AddObject: FirstName, LastName];
FirstName = @ "FN2";
LastName = @ "LN2";
[person AddObject: FirstName, LastName];
//etc. ...
I know that AddObject can only add 1 object but it is to explain the concept of my example.
How can I add 2 objects at the same time like in my example?
then, how can i manage/retrieve objects NString "1" (firstName) & NString "2" (lastName) by the index (i);
I confess I can not find the logic of development and your responses would be very helpful.
Thank you very much for your reply.
EDIT :
I have a strange problem. My .m :
Person *pers = [[Person alloc]init];
NSMutableArray *myarray = [[NSMutableArray alloc] init];
[pers setFirstName:@"FN 1"]; // = pers.firstName;
[pers setLastName:@"LN 1"]; // = pers.lastName;
[myarray addObject:pers];
[pers setFirstName:@"FN 2"];
[pers setLastName:@"LN 2"];
[myarray addObject:pers];
[pers release];
NSLog(@"count: %d", [myarray count]);
for(int i = 0; i < [myarray count]; i++)
{
pers = [myarray objectAtIndex:i];
NSLog(@"%d %@ %@ %@", i, pers, pers.firstName, pers.lastName);
}
[myarray release];
and my NSLog is : 2011-04-27 19:07:57.582 temp[11724:903] count: 2
2011-04-27 19:07:57.584 temp[11724:903] 0 FN 2 LN 2
2011-04-27 19:07:57.585 temp[11724:903] 1 FN 2 LN 2
As you can see, i have FN 2 LN 2 twice. Object "pers" have twice the same value
Normal ?