//ARC is turned on in Xcode 4.2
A static function is created which executes a query and gets the values from the database SQLite.
The array values returned by the function displayquery is an array of a no of mutable arrays which contain the records.
I want to convert it into client objects and store the list list in an NSMutable object before returning it.
static function
+ (NSMutableArray*) list
{
NSString *querySQL = //some query;
NSMutableArray *values = [Client displayQuery:querySQL numberOfColumns:7];
NSMutableArray *lst = nil;
if (values != nil)
{
lst = [NSMutableArray arrayWithObject:@"Client"];
for (int i = 0; i<[[values objectAtIndex:0] count] ; i++)
{
[lst addObject:[Client new ]];
}
for (int i = 0; i<[[values objectAtIndex:0] count] ; i++)
{
Client *aClient = [lst objectAtIndex:i];
//error occurs during the execution of this line.
//all properties of Class client are (retain,nonatomic)
aClient.idClient = [[values objectAtIndex:0]objectAtIndex:i];
aClient.prenom = [[values objectAtIndex:1]objectAtIndex:i];
aClient.name = [[values objectAtIndex:2]objectAtIndex:i];
aClient.address = [[values objectAtIndex:3]objectAtIndex:i];
aClient.telephone = [[values objectAtIndex:4]objectAtIndex:i];
aClient.email = [[values objectAtIndex:5]objectAtIndex:i];
aClient.weight = [[values objectAtIndex:6]objectAtIndex:i];
[lst addObject: aClient];
}
}
return lst;
}
The problem is that the first element in your
lstarray is anNSString, which does not have any of the properties that yourClientclass has, and when you try to assign to it, you get an error. There are a few issues in your code:@"Client"as an element in your array, since it doesn’t seem like it belongs there.Clientobjects to the array. Just create them and add them to the array as you go.I think your code should look more like this: