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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:41:22+00:00 2026-06-13T10:41:22+00:00

Similar to a Javascript-Object I need to store boolean values and nil values in

  • 0

Similar to a Javascript-Object I need to store boolean values and nil values in an objective-C NSDictionary. (This problem did raise when I tried to write an universal JSON-Parser) (Yes, I know there are some good ready-to-use-parsers out there, but I wanted to try to write my own.)

This is an example for what I want to do:

NSString* str = @"a string";
NSNumber* num = @123.456;
NSArray*  arr = @[@"abc",@99];
boolean   boo = true;
id        obj = nil;

NSDictionary* dict = @{
    @"key1" : str,
    @"key2" : num,
    @"key3" : arr,
    @"key4" : boo,   //will not work since boo is not an object
    @"key5" : obj    //will not work since obj is nil
};

//later in the same piece of code:

dict = @{
    @"key1" : str,
    @"key2" : num,
    @"key3" : arr,
    @"key4" : @1,  //Here we have the NSNumber 1 assigned to key4
                   //(which is not the boolean value true)
    @"key5" : @""  //an empty NSString-Object (which is not nil)
};

boolean
One solution could be, that I do this:

    ...
    @"key4" : [NSNumber numberWithBool:boo];
    ...

But if boo is true the result would be exactly the same as

    ...
    @"key4" : @1;
    ...

If it was false, it would be identic to

    ...
    @"key4" : @0;
    ...

But I need to know if the original value was a boolean value or a numeric number.

nil vs. placeholder-object
Instead of asigning nil as a value to the dictionary I could use a placeholder like an empty string (@””), a certain number (-1) or something else. But later, I have no chance to find out, if I did store the placeholder because I wanted to store nil, or if I did store a valid value that by accident is identic to my placeholder.

  • 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-13T10:41:23+00:00Added an answer on June 13, 2026 at 10:41 am

    If you are not able to use NSNumber to encapsulate the BOOL, nor NSNull, your next option is to create your own wrapper class:

    @interface MyBoolean : NSObject
    @property (nonatomic, assign) BOOL boolVal;
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, I've tried to search answer for this problem and I found many similar
This is similar to: How to open a file using JavaScript? Goal: to retrieve/open
I want to use a javascript countdown function similar to this http://jsfiddle.net/Apnu2/6/ when a
I have something very similar to this example: https://developers.google.com/maps/documentation/javascript/examples/directions-simple All I am trying to
I'm not very experienced with JavaScript, but this code was similar to what I
I know there are a LOT of similar question to this, but I've tried
Does jQuery have a JSON/Javascript object to HTML pretty print function similar to PHP's
Is it possible to create a property on a javascript object that behaves similar
Sometimes I need a more complex object in JavaScript and I usually do something
Referring on this question , I have a similar -but not the same- problem..

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.