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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:11:59+00:00 2026-05-18T04:11:59+00:00

First off I confess my ignorance, I’ve learned everything I know about Objective-C in

  • 0

First off I confess my ignorance, I’ve learned everything I know about Objective-C in the few months I’ve been working on my project. I also find it utterly frustrating how Objective-C seems to complicate what would be simple matters in any other language I’ve worked with. This question is a case in point…

In the first run my app downloads a bunch of JSON which it uses to populate a CoreData store. I use an Obj-C/JSON library (CJSONDeserializer) to convert the JSON to NSArrays. In the JSON download for one CoreData entity there’s a field containing a number ("show_id":2) identifying the related field in another entity if there is one or null ("show_id":null) otherwise. In processing that field I assign it to an NSNumber using…

NSNumber *shoIndex = [[item objectForKey:typeKey] objectForKey:@"show_id"];

I then try to check that I have a valid number before attempting to fetch & link the related record so as to not do wasteful processing where there is no related record.

Interrogating shoIndex with…

NSLog(@"shoIndex: %i, %@, %@", shoIndex, shoIndex, [shoIndex description]);

Gives…

shoIndex: 19590600, <null>, <null>

where the JSON value was null &…

shoIndex: 228300880, 51, 51

otherwise.

So far the only successful check I’ve made is with…

if (![[shoIndex description] isEqualToString:@"<null>"]) {

Can anyone suggest a better way?

Update…

Looking at it another way shoIndex is assigned as a NSNumber that sometimes contains a NSString value @"<null>". Does Obj-C have something like an isa operator that I could use to check the type of the contents of shoIndex?

TIA, Pedro.

  • 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-18T04:11:59+00:00Added an answer on May 18, 2026 at 4:11 am

    Use [shoObject class] to get the class of an object; so, to test shoObject‘s class, you would use

    [shoObject isKindOfClass:[NSString class]];
    

    Once you’ve sorted out what markers define an empty string or NSNumber, you can create a macro. I do with this by keeping an IsEmpty macro in a file called CommonMacros.h. Here’s the code:

    //Thanks Wil
    //http://wilshipley.com/blog/2005/10/pimp-my-code-interlude-free-code.html
    
    static inline BOOL IsEmpty(id thing) {
        return thing == nil
        || ([thing isEqual:[NSNull null]]) //JS addition for coredata
        || ([thing respondsToSelector:@selector(length)]
            && [(NSData *)thing length] == 0)
        || ([thing respondsToSelector:@selector(count)]
            && [(NSArray *)thing count] == 0);
    }
    

    Then, after importing CommonMacros.h, you can call the function like this:

    if (IsEmpty(shotIndex)) {
        //do stuff
    }
    

    This should take care of this problem, and will also work on strings, arrays, etc, as you can see from the code. Thanks to Wil Shipley!

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

Sidebar

Related Questions

First off, I know next to nothing about language theory, and I barely know
First off I know this has been covered on SO. But the most popular
First off I've been working with Java's Concurrency package quite a bit lately but
First off, I'm working on an app that's written such that some of your
First off, I know this may be a very stupid question, so don't shoot
First off, apologies if this question has been asked before but I couldn't find
First off, I know my title can be formulated better, but my math classes
First off - apologies if this or a similar question has been asked before.
First off, I think I know what's going on, but I thought I'd bring
First off, the barest bones of the project I wish to create is 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.