开发者

Iphone sdk setting object attributes with array (sqlite3)

Not sure if this is possible in Iphone sdk since i have not been able to get it working. I have an object called Client, and it has the following properties.

  firstName, lastName, mobile, email.

i then set it up by doing the following

  Client *clientObj = [[Client allo开发者_Python百科c] init:];

i then set up an array with the following values, which has the exact attribute names for Client.

  NSArray *myArray = [[NSArray alloc]initWithObjects:@"firstName", @"lastName", @"email", @"mobile", nil]

now, is it possible to do something like this

  clientObj.[myArray objectAtIndex:0] = @"Robert";

to get the same effect as doing

  clientObj.firstName = @"Robert";

Has anyone been able to do something similar? The reason i am doing it this way is that i have an IF statement that checks if an sql statement returns a null value for a field, so therefore it wont assign it to the clientObj and the only way i thought i could iterate through the attributes of Client is to set up and array which has those attributes.

This was a section of my code i was working on.

  Client *clientObj = [[Client alloc] init];

  int i;

  NSArray *myArray = [[NSArray alloc]initWithObjects:@"firstName", @"lastName", @"email", @"mobile", nil];

  for(i=0;i < [myArray count];i++){

  char *tempChar = sqlite3_column_text(selectstmt, i);                            

  if (tempChar == nil) {
     //is null dont assign
  } else { 
     clientObj.[myArray objectAtIndex:i] = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, i)];
  }


Instead of using the dot syntax use KVC [clientObj setValue:@"Robert" forKey:[myArray objectAtIndex:i]];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜