Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7926643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:51:26+00:00 2026-06-03T18:51:26+00:00

I created an entity with a float attribute and set it’s value to 0.5

  • 0

I created an entity with a float attribute and set it’s value to 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];
}

From the log, the value of the float is still 0.5000

But when I fetch it later on, the value somehow became 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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:51:28+00:00Added an answer on June 3, 2026 at 6:51 pm
    +(void)createSportNamed:(NSString *)name withContext:(NSManagedObjectContext *)context{
      Sport *newSport = [NSEntityDescription insertNewObjectForEntityForName:@"Sport" inManagedObjectContext:context];
      newSport.name = name;
    

    This clearly shows that the “name” field of your Sport entity is a string.

    [NSPredicate predicateWithFormat:@"name == %d",sportName]
    

    And yet here you are using %d, which means int. You’re casting a string pointer to an int. You should be using %@. Thus, your fetch request is returning an empty array, and -lastObject is returning nil, which means that [nil endurance] is also nil, which means that [[nil endurance] floatValue] is also nil, or 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a simple custom attribute on the sales/order entity. Now, for new orders,
I have created an entity data model and generated a database from it. One
I cannot update created previously entity. I'm getting a StaleObjectException exception with message: Row
Entity Framework has created the required partial classes. I can add these partial classes
I've created a DAL using the entity framwerok. I've also created a business service
I have created a new application using Entity Framework 4.3 database migrations. The migrations
I've created a class library that contains three entity models for three databases that
I've created a very simple Enterprise Application project with about 7 entity beans and
I have created a Dynamic Data site against an Entity Framework Model I have
I have an Entity Data Model that I have created, and its pulling in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.