我有以下代码,这是正常的。
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context];
request.entity = entity;
NSArray *results = [context executeFetchRequest:request error:&err];
NSLog(@"results.count = %d", results.count);
记录'results.count = 2',其中2是我上下文中的所有注册人。 但是,当我尝试修改此代码以仅带来属性时,它会带来0个对象。
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context];
request.entity = entity;
request.resultType = NSDictionaryResultType;
request.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"name"]];
NSArray *results = [context executeFetchRequest:request error:&err];
NSLog(@"results.count = %d", results.count);
有人知道我做错了什么吗?我找不到答案。