fetchRequest를 필터링하려고합니다.Xcode - NSFetchRequest를 필터링하고 각 객체를 선택하십시오.
결과가 NSArray에로드되는 지점에 있습니다.
그러나 개별 항목을 꺼내기 위해 배열을 구문 분석해야합니다. 지금 당장은 하나의 객체처럼 보입니다.
나는이 지점에 도착하기 위해 사용하고 코드는 다음과 같이이 결과
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = coreDataController.mainThreadContext;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Category" inManagedObjectContext:moc];
[request setEntity:entity];
// Order the events by name.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[request setSortDescriptors:@[sortDescriptor]];
// Execute the fetch -- create a mutable copy of the result.
NSError *error = nil;
NSArray *categories = [[moc executeFetchRequest:request error:&error] mutableCopy];
if (categories == nil) {
NSLog(@"bugger");
}
NSObject *value = nil;
value = [categories valueForKeyPath:@"name"];
: 또한
value = (
)
[DetailViewController loadPickerArray]
[AppDelegate loadPickerArray]
value = (
"Cat Two",
"Cat Three",
"Cat One",
"Cat Four"
)
, 처음이 달려 있음을 유의하시기 바랍니다, 거기 없음 결과. 나는 그 시간의 약 50 %를 얻는다.
도움 주셔서 감사합니다.
나는 당신이하려는 것을 이해하지 못합니다. '필터'란 특정 조건을 충족하는 반품을 의미합니까? 그렇다면 왜 당신은 당신의 요청에'NSPredicate'를 첨부하지 않으시겠습니까? –
카테고리 엔티티에는 세 개의 필드가 있으며이 목적을 위해 이름 만 필요합니다. 나는 그것을 얻었지만 4 개가 아니라 하나의 객체 (괄호 안의)로 반환합니다. 나는 내가 뭘 잘못하고 있는지 몰라. –
'categories'는 배열이고,'valueForKeyPath :'를 호출하면 배열에있는 각 객체의 값 (keypath)을 가진 배열을 반환합니다. –