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

  • Home
  • SEARCH
  • 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 6174239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:43:06+00:00 2026-05-23T23:43:06+00:00

I have a CoreData model with 2 objects. The first object (Images) contains a

  • 0

I have a CoreData model with 2 objects. The first object (Images) contains a list of image names. The second object (Book) has a relationship with a field from the Images object called imageId. The data type is set to int16 and is marked optional with a default value of 0, as not every book will have an image.

I request a JSON representation of the Book object from a WCF service. One of the book objects returned has “ImageId” : null as its value. So when converting the JSON object into a managed object in Objective-C I get the following error message:

Unacceptable type of value for attribute: property = “imageId”; desired type = NSNumber; given type = NSNull; value =

How do you handle this conversion? I thought of checking for null and then setting the value to 0 but this doesn’t seem correct.

Many thanks.

*UPDATE *
In the process of implementing Daniels solution I discovered that other fields could also be returned from the service as null. Is it therefore possible to modify the NSDictionary category to enable it to traverse itself and replace any instance of with nil? I am using jsonKit as my JSON parser and it seems to return the parsed result as a NSMutableDictionary with NSDictionary objects representing my JSON objects. I have spent much of the day trying to modify my objects but as they are returned as NSDictionaries they are immutable. I could simply use Daniels solution on every field that needed checking for however if the service changed and another field was returned as then this would break my app. Alternatively I could implement Daniels solution on every field just incase it was ever but not sure if thats a good solution especially for performance.

  • 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-05-23T23:43:07+00:00Added an answer on May 23, 2026 at 11:43 pm

    Some JSON libraries let you set an option so that JSON nulls are simply omitted from the dictionary as opposed to using NSNull. If you do that, then it will work because [theDict objectForKey:@"imageID"] will return nil.

    But other than that, the right thing to do is look out for NSNull explicitly. Making an NSDictionary category is a handy way to do it:

    @implementation NSDictionary (DDNullGetter)
    
    - (id)nonNullObjectForKey:(id)key
    {
        id val = [self objectForKey:key];
        return (val == [NSNull null] ? nil : val);
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have a CoreData entity named, say, 'Book', which has a one-to-one relationship
In my Core Data model I have two entities: List and Patient. List has
I have Week model that has Day as child objects. There is days relation
I have a CoreData model (managed object) called Item: @interface Item : NSManagedObject {
I have a to-many relationship in my CoreData model without an inverse relationship which
CoreData beginner I have a simple problem with CoreData. My model has two entities,
I have set up a Core Data model where I have two objects, say
In my Core Data managed object model, I have an entity Foo with a
I have a sqlite DB created by my CoreData model automatically, but my app
In my core data model I have a Person entity that has a to

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.