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 7769999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:17:59+00:00 2026-06-01T16:17:59+00:00

I am writing an application using Core Data which heavily depends on setting attributes

  • 0

I am writing an application using Core Data which heavily depends on setting attributes from string values. However, I am running into a problem because Core Data, when it creates wrapper methods, uses NSNumber to represent all of the numeric fields. Therefore, if I pass in a String using key/value coding setValue:forKey: it gives me a type error:

For instance, I have an object type “Building”. In the datamodel, I have an attribute called “fbFloors” set to integer 32.

Then, in my code, I do the following:

Building * b = [NSEntityDescription insertNewObjectForEntityForName:@”Building” inManagedObjectContext:ctx];
[b setValue:@”2″ forKey:@”fbFloors”];

This raises the following exception:

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Unacceptable type of value for attribute: property = “fbFloors”; desired type = NSNumber; given type = __NSCFConstantString; value = 2.’

I would like it to coerce the string value to a number, but it doesn’t want to. I tried implementing coerceValueForFbFloors: but it looks like that is only available in Mac OS X, not iOS.

Any ideas?

  • 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-01T16:18:00+00:00Added an answer on June 1, 2026 at 4:18 pm

    You have to pass an actual instance of NSNumber to setValue. Something like:

    [b setValue[NSNumber numberWithInt:2] forKey:@”fbFloors”];

    If your data is appearing as a string, then you can use NSNumberFormatter to convert it first to an NSNumber.

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

Sidebar

Related Questions

I am writing an application using Core Data to control a few NSTableViews. I
I am writing a server application using Boost Asio: Server: Running io_service.run() from pool
I am writing an application using the MVVM pattern. I am providing data to
I'm currently writing an application using Vala that requires me to send data over
I am writing a Core Data ContextManager for a larger iOS application. A ContextManager
I am writing a Console application using C#, in which I am firing Print
I am writing an application using labview and need to use external code. I
I'm writing an application using DDD techniques. This is my first attempt at a
I have been writing an application using ASP.Net MVC4, where the majority of the
I'm writing an application using WPF, and I need to make something that looks

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.