【问题标题】:core data simple Fetch核心数据简单 Fetch
【发布时间】:2011-12-14 12:12:40
【问题描述】:

我正在使用 coredata 来检查实体的内容,但仍然记得如何去做,

PFIWIAppDelegate* delegate = (PFIWIAppDelegate*)[[UIApplication sharedApplication] delegate];


NSEntityDescription *entity = [NSEntityDescription entityForName:@"productPoints" inManagedObjectContext:[delegate managedObjectContext]]; 

NSFetchRequest *request = [[NSFetchRequest alloc] init]; 

[request setEntity:entity];

NSLog(@" la resposta por deux:: %@", request);


NSError *error = nil;
NSArray *results = [[delegate managedObjectContext] executeFetchRequest:request error:&error];

NSLog(@"tu fetch master db ::%@",results);

所以我确定我的实体“productPoints”中有属性[在 sqlite 管理器中检查)

如何查看数据?

在我的日志中我看到

la resposta por deux:: <NSFetchRequest: 0x6cd1780> (entity: productPoints; predicate: ((null)); sortDescriptors: ((null)); type: NSManagedObjectResultType; )
2011-12-14 14:50:44.266 PFIWIN0196[7524:fb03] tu fetch master db ::(
"<productPoints: 0x6cd38c0> (entity: productPoints; id: 0x6cd2ce0 <x-coredata://888E340F-6CBF-4EED-B9D9-9C3FB06244F3/productPoints/p6> ; data: <fault>)",
"<productPoints: 0x6cd3b70> (entity: productPoints; id: 0x6cd2cf0 <x-coredata://888E340F-6CBF-4EED-B9D9-9C3FB06244F3/productPoints/p7> ; data: <fault>)"

所以我猜我看到了我的实体的 2 个对象,但是如何查看属性,

谢谢!

【问题讨论】:

    标签: ios core-data fetch


    【解决方案1】:

    您的对象在results 数组中,正如您所猜测的那样。要查看属性,您所要做的就是访问它们,使用以下内容:

    productPoints* firstProduct = [results objectAtIndex:0];
    NSLog("Some property value:  %@", firstProduct.someProperty);
    

    还请注意,标准的核心数据 API 对于一个应该简化存储和检索数据任务的框架来说是绝对荒谬的。我强烈建议你尝试使用讨论过的NSManagedObjectContext+EasyFetch 类别here 和github 中的here

    那么你的代码可以改写为:

    PFIWIAppDelegate* delegate = (PFIWIAppDelegate*)[[UIApplication sharedApplication] delegate];
    NSArray* results = [[delegate managedObjectContext] fetchObjectsForEntityName: @"productPoints"];
    NSLog(@"tu fetch master db ::%@",results);
    

    【讨论】:

    • 太棒了!谢谢!,对于答案和>NSManagedObjectContext+EasyFetch
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    • 2011-11-08
    • 2010-11-13
    • 1970-01-01
    相关资源
    最近更新 更多