开发者

Record data to attributes in core data Iphone

I have about 20 entity : Event1 ... Event20 In each entity i have property values1 ... values20

I need record data in for example Event5 values8

But something wrong - may be data record in each 开发者_高级运维values8 (Event1 ... Event20)

How do right?

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


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

 NSFetchRequest *fetchRequests = [[NSFetchRequest alloc] init];
NSEntityDescription *entit = [NSEntityDescription entityForName:str      inManagedObjectContext:app.managedObjectContext];

   [fetchRequests setEntity:entit] ;
   [fetchRequests setPropertiesToFetch :[NSArray arrayWithObject:value]];  
    [fetchRequests setReturnsDistinctResults:YES];
   NSError *error;
      NSArray *fetchedObject = [app.managedObjectContext executeFetchRequest:fetchRequests error:&error];
      NSManagedObject *fetched = nil;
     NSManagedObject *fetch = nil;
      printf("\n%d", [fetchedObject count]);


The code below retrieves values in Entity5 for Value8 equal to someValueForEight.text (UITextField). This should help you out.

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

        NSManagedObjectContext *context = [app managedObjectContext];
        NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Entity5" inManagedObjectContext:context];
        NSFetchRequest *request = [[NSFetchRequest alloc] init];

        [request setEntity:entityDesc];
        NSPredicate *pred = [NSPredicate predicateWithFormat:@"(value8 = %@)", someValueForEight.text];
        [request setPredicate:pred];

        NSManagedObject *matches = nil;
        NSError *error;

        NSArray *objects = [context executeFetchRequest:request error:&error];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜