2010-12-05 2 views
0

코어 데이터 엔티티로 해결할 수없는 문제가 있습니다.Coredata 플로트 번호가 0이됩니다

내 엔티티에는 두 개의 관계 (whoHasToPay, whoHasToBePaid)와 속성 (howMuch)이 있습니다.

내가 데이터베이스에 레코드를 삽입하는 코드입니다

Debitcredit *dc = [NSEntityDescription 
    insertNewObjectForEntityForName:@"Debitcredit" 
    inManagedObjectContext:self.context]; 
dc.howMuch = [NSNumber numberWithFloat:5.2f]; 
dc.whoHasToPay = theDebitor; 
dc.whoHasToBePaid = theCreditor; 
NSLog(@"%@", dc); 
[self.context save:&error]; 

NSLog는

<Debitcredit: 0x151590> (entity: Debitcredit; id: 0x141570 
    <x-coredata:///Debitcredit/t8DC4691F-5DE3-42D5-8095-C2D5D3264C8D2> ; data: { 
    howMuch = "5.2"; 
    whoHasToBePaid = "0x140c50 <x-coredata://C25DC4FE-B46B-402C-B513-A2A83C6A9F86/Users/p1>"; 
    whoHasToPay = "0x14c280 <x-coredata://C25DC4FE-B46B-402C-B513-A2A83C6A9F86/Users/p2>"; 
}) 

그렇게 값 howMuch이 올 것 같다 보여줍니다. 그러나

, 내가

fetchRequestCount = [[NSFetchRequest alloc] init]; 
entityCount = [NSEntityDescription entityForName:@"Debitcredit"  
    inManagedObjectContext:self.context]; 
[fetchRequestCount setEntity:entityCount]; 
fetchedObjectsCount = [self.context executeFetchRequest:fetchRequestCount error:&error]; 
for (Debitcredit *dc in fetchedObjectsCount) { 
    NSLog(@"%f", [dc valueForKey:@"howMuch"]); 
    NSLog(@"%@", [[dc valueForKey:@"whoHasToPay"] name]); 
    NSLog(@"%@", [[dc valueForKey:@"whoHasToBePaid"] name]); 
} 
[fetchRequestCount release]; 

로 다시 호출 할 때 NSLog는

2010-12-05 01:47:04.636 myApp[6179:307] 0.000000 
2010-12-05 01:47:04.642 myApp[6179:307] John 
2010-12-05 01:47:04.646 myApp[6179:307] Jack 

을 보여줍니다 howMuch이 제로가 될 것 같다. 왜? 내가 잘못?

답변

3

로깅 오류입니다. 수레 및 기타 숫자 값은 NSNumber 객체로 저장됩니다. 이것은 :

[dc valueForKey:@"howMuch"] 

...는 NSNumber 객체를 반환하고 float 값은 반환하지 않습니다. 로그를 다음과 같이 변경해야합니다.

NSLog(@"%@", [dc valueForKey:@"howMuch"]); 

... 올바른 값을 확인해야합니다.

+0

감사합니다. 이제 작동합니다! –