float 属性を持つエンティティを作成し、その値を 0.5 に設定しました
+(void)createSportNamed:(NSString *)name withContext:(NSManagedObjectContext *)context{
Sport *newSport = [NSEntityDescription insertNewObjectForEntityForName:@"Sport" inManagedObjectContext:context];
newSport.name = name;
newSport.maxRep = [NSNumber numberWithInt:45];
newSport.endurance = [NSNumber numberWithFloat:0.5f];
NSLog(@"endurance at set = %f",[newSport.endurance floatValue]);
NSError *saveError = nil;
[context save:&saveError];
}
ログから、フロートの値はまだ 0.5000 です
しかし、後で取得すると、値はどういうわけか0.0000になりました
-(NSArray*)createWorkoutForSport:(NSString*)sportName withContext:(NSManagedObjectContext*)context{
NSFetchRequest *request = [NSFetchRequest new];
request.entity = [NSEntityDescription entityForName:@"Sport" inManagedObjectContext:context];
NSPredicate *sportNamePredicate = [NSPredicate predicateWithFormat:@"name == %d",sportName];
request.predicate = sportNamePredicate;
NSError *err = nil;
NSArray *results = [context executeFetchRequest:request error:&err];
Sport *theFetchedSport = [results lastObject];
int totalRep = [[theFetchedSport maxRep]intValue];
float endure = [[theFetchedSport endurance]floatValue];
int set;
NSLog(@"Endurance = %f",endure);