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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:20:22+00:00 2026-05-19T01:20:22+00:00

I have a core data object that has a bunch of optional values. I’m

  • 0

I have a core data object that has a bunch of optional values. I’m pushing a table view controller and passing it a reference to the object so I can display its contents in a table view. Because I want the table view displayed a specific way, I am storing the values from the core data object into an array of dictionaries then using the array to populate the table view. This works great, and I got editing and saving working properly.
(i’m not using a fetched results controller because I don’t have anything to sort on)

The issue with my current code is that if one of the items in the object is missing, then I end up trying to put nil into the dictionary, which won’t work.

I’m looking for a clean way to handle this, I could do the following, but I can’t help but feeling like there’s a better way.

*passedEntry is the core data object handed to the view controller when it is pushed, lets say it contains firstName, lastName, and age, all optional.

if ([passedEntry firstName] != nil) {
    [dictionary setObject:[passedEntry firstName] forKey:@"firstName"]
}
else {
    [dictionary setObject:@"" forKey:@"firstName"]
}

And so on. This works, but it feels kludgy, especially if I end up adding more items to the core data object down the road.

  • 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-19T01:20:22+00:00Added an answer on May 19, 2026 at 1:20 am

    What you could do is iterate through all of the object’s properties using the objc_* runtime functions like so:

    unsigned int property_count;
    objc_property_t * prop_list = class_copyPropertyList([CoreDataObject class], &property_count);
    
    for(int i = 0; i < property_count; i++) {
       objc_property_t prop = prop_list[i];
       NSString *property_name = [NSString stringWithCString:property_getName(prop) encoding:NSUTF8StringEncoding];
       id obj = [passedEntry valueForKey:property_name];
       [dictionary setObject:((obj != nil) ? obj : [NSNull null]) forKey:property_name];
    }
    
    free(prop_list);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object in core data that has 2 fields: Name and Date.
I have a core data recipe object that contains an ordered list of ingredient
Say I have core data objects of type obj that has a property propertyA
In my Core Data managed object model, I have an entity Foo with a
I have a relationship in a Core Data model that feels like it wants
I have a set of core, complicated JavaScript data structures/classes that I'd like to
I have a core data based app I am working on, that uses an
I have a core file generated on a remote system that I don't have
I have a delete statement that's going against one of my core application tables.
This is the Core Data object model I am working with (I am a

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.