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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:51:12+00:00 2026-06-12T06:51:12+00:00

Wy does NSUserDefaults objectForKey method, returns a string with 0 and not nil? Documentation

  • 0

Wy does NSUserDefaults objectForKey method, returns a string with “0” and not nil?

Documentation states,

Return Value
The object associated with the specified key, or nil if the key was
not found.

NSDate * date = [[NSUserDefaults standardUserDefaults] objectForKey:OVERTIME_RATE_MARKER];

    if (date) {
      //something
    }

The conditional statement above, always executes, because if the object is not found, it’s returning an object of class: __NSCFString with “0”. When it should be returning “nil”

I can of course, test the string for “0”. But I don’t really want to do that.

I also tried to use ID for type. I keep getting a __NSCFString with “0”.

Can anyone help me figure this out?

Any help is appreciated!

Thank you

  • 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-12T06:51:13+00:00Added an answer on June 12, 2026 at 6:51 am

    This API definitely returns nil when the key doesn’t exist. Either the key was already set in your preferences, or you’re setting it to @"0" somewhere else in your code before this code that reads it.

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

Sidebar

Related Questions

Does anyone know how to store an array in Monotouch NSUserDefaults? One possible method:
When and why does NSUserDefaults' synchronize method fail? What is the best way to
When I try to use NSUserDefaults on two different screens, the NSUserDefaults does not
Does anyone know why UsernameExists wont return True. I must have my syntax messed
In my prepareForSegue method, I pass an immutable array retrieved from NSUserDefaults to a
I'm using NSUserDefaults to keep an object in sync across several UIViewController s that
Does anyone know where/how does NSUserDefaults store the information for persistence? I'm just curious
I am storing a username/password in NSUserDefaults. I do not want this information to
What I expect to happen: I create an NSUserDefaults object with a username (NSString
I'd like to add functional data in the NSUserDefaults object but I'm a little

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.