nsfetchRequest에 올바른 수의 객체를 반환하지만 각 객체에는 nil 속성이 포함되어 있습니다.

StackOverflow https://stackoverflow.com/questions/2406021

  •  18-09-2019
  •  | 
  •  

문제

왜 이런 일이 일어나고 있는지 알 수 없습니다. 컨텍스트에 추가 할 수 있습니다. 그러나 객체를 검색하면 올바른 객체 수를 반환하지만 객체의 속성은 Null입니다.

이 코드와 함께 3 개의 인스턴스를 추가하고 있습니다.

+(bool) addStoreWithId : (nsnumber *) ID 위도 : (nsnumber *) 위도 경도 : (nsnumber *) 경도 이름 : (nsstring *) 이름 {

Stores *store = (Stores *)[NSEntityDescription
                    insertNewObjectForEntityForName:@"Stores" 
                    inManagedObjectContext:[[SharedResources instance] managedObjectContext]];

store.ID = ID;
store.Latitude = latitude;
store.Longitude = longitude;
store.Name = name;
NSError *error;
if(![[[SharedResources instance] managedObjectContext] save:&error])
{
    //Handle the error
    return NO;
}
return YES;

} 결과를 얻습니다 : 2010-03-07 19 : 19 : 37.060 GamePouch_iphone [11337 : 207] 상점 이름은 Starbucks (GDB) 계속 2010-03-07 19 : 19 : 37.933 Gamepouch_iphone [11337 : 207] 상점 이름은 Dunkin입니다. 도넛 (GDB) 계속 2010-03-07 19 : 19 : 38.717 GamePouch_iphone [11337 : 207] 상점 이름은 Krispy Kreme입니다.

이 코드가 세 번 방문되었으며 속성 중 어느 것도 NIL이 아니 었음을 확인했습니다.

그런 다음 검색하려고하면 다음 코드를 사용합니다.

+(nsMutableArray *) fetchAllObjects {

NSFetchRequest *request;
request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Stores" inManagedObjectContext:[[SharedResources instance] managedObjectContext]];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ID" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
NSError *error;
NSMutableArray *array = [[[SharedResources instance] managedObjectContext] executeFetchRequest:request error:&error];
[request release];
[sortDescriptor release];
[sortDescriptors release];
for(int i=0;i<3;i++)
{
    Stores *tempStore = (Stores *)[array objectAtIndex:i];
    NSLog(@"store name is %@",[tempStore Name]);
}
return array;

}

결과를 얻는다 : 2010-03-07 19 : 21 : 00.504 GamePouch_iphone [11337 : 207] 상점 이름은 (null) (GDB) 계속 2010-03-07 19 : 21 : 01.541 GamePouch_iphone [11337 : 207] 상점 이름입니다. (NULL) (GDB) 계속 2010-03-07 19 : 21 : 02.503 GamePouch_iphone [11337 : 207] 상점 이름은 (null)

읽어 주셔서 감사합니다. 어떤 도움이든 큰 감사를드립니다.

감사합니다 Bakhtiyar uddin

도움이 되었습니까?

해결책

문제가 무엇인지 알 수 있습니다.

tempstore name] 대신 [tempstore valueforkey :@"name"]를 사용해야했습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top