views:

103

answers:

0

I create entity Event Each entity has values1...values100 property

values- indexed optional Int16

each values write 30 number

Do

NSString *str = [NSString stringWithFormat:@"Event", variable];
NSString *value  = [NSString stringWithFormat:@"values%d", vari];



 TermometrAppDelegate *app;
 app = (TermometrAppDelegate *)[UIApplication sharedApplication].delegate;

    for (int h=0;h<30;h++){
NSManagedObject *Event = [NSEntityDescription insertNewObjectForEntityForName:str inManagedObjectContext:app.managedObjectContext]; 
[Event setValue:[NSNumber numberWithInt:buf4[v+h]] forKey:value]; 
[app.managedObjectContext save:nil] ;    }




 NSFetchRequest *fetchRequests = [[NSFetchRequest alloc] init];
 NSEntityDescription *entit = [NSEntityDescription entityForName:str  inManagedObjectContext:app.managedObjectContext];
 NSError *error;
 NSArray *fetchedObject = [app.managedObjectContext executeFetchRequest:fetchRequests error:&error];
 NSManagedObject *fetched ;
 NSManagedObject *fetch ;
    printf("\n%d", [fetchedObject count]);

for (int n=0;n<30;n++){
    fetch=[fetchedObject objectAtIndex:n];
int plus=[[fetch valueForKey:value] intValue];
    printf("\n%d", plus);
}

If i write in event first values78 - Ok

If i write in event second values7 - i get 0 0 0 0 0 0 0 0 ...

Also i try another way - but get EXC_Bad_Access

    NSString *value;
if (k==0) value  = [NSString stringWithFormat:@"values1", vari]; 
    else value  = [NSString stringWithFormat:@"values10", vari];    

k=k+1;
TermometrAppDelegate *app;
app = (TermometrAppDelegate *)[UIApplication sharedApplication].delegate;




        [app.managedObjectContext setRetainsRegisteredObjects:YES];

printf("\n%d", buf4[v]);         
    for (int h=0;h<30;h++){
NSManagedObject * Event = [NSEntityDescription insertNewObjectForEntityForName:str inManagedObjectContext:app.managedObjectContext]; 
            [Event setValue:[NSNumber numberWithInt:buf4[v+h]] forKey:value]; 
    [app.managedObjectContext save:nil] ;}




 NSFetchRequest *fetchRequests = [[NSFetchRequest alloc] init];
 NSEntityDescription *entit = [NSEntityDescription entityForName:str  inManagedObjectContext:app.managedObjectContext];
 NSError *error;
 NSArray *fetchedObject = [app.managedObjectContext executeFetchRequest:fetchRequests error:&error];
 NSManagedObject *fetch ;
    printf("\n%d", [fetchedObject count]);

for (int n=0;n<30;n++){
    fetch=[fetchedObject objectAtIndex:n];
int plus=[[fetch valueForKey:value] intValue];
    printf("\n%d", plus);
}