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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:48:43+00:00 2026-05-19T04:48:43+00:00

I’ve written a large social networking iPhone application, and one of the biggest issues

  • 0

I’ve written a large social networking iPhone application, and one of the biggest issues I run into is the fact that NSInteger (and all the other NS-non-object types) are not first class citizens. This problem stems from the fact that, obviously, they have no representation for a nil value.

This creates two main problems:

  1. Tons of overhead and opaqueness to convert to and from NSNumber when storing/retrieving from a collection.
  2. Can’t represent nil. Oftentimes, I want to be able to represent an “unset” value.

One way to solve this is to use NSNumber all the time, but that gets extremely confusing. In a User model object, I would have about 20 different NSNumbers, and no easy way to tell if each one is a float, integer, bool, etc.

So here are my thoughts for potential solutions and the pros/cons. I’m not really sold on any of them, so I thought I’d ask for feedback and/or alternative solutions to this problem.

  1. Continue to use NSInteger types, and just use NSIntegerMax to represent nil.
    PRO – Less memory overhead
    PRO – Clear typing
    CON – NSIntegerMax is not really nil. If programmers aren’t careful or don’t know this convention, invalid values could leak into the display layer.
    CON – Can’t store them in a collection without conversions in and out

  2. Use NSNumber and designate types using hungarian notation (eg NSNumber fHeight, NSNumber iAge)
    PRO – First-class citizens
    PRO – Nil problem solved
    CON – Increased memory overhead
    CON – Lose compiler type checking
    CON – Hungarian notation is contentious

  3. Write my own first-class primitive object types (think Java http://developer.android.com/reference/java/lang/Integer.html)
    PRO – First-class citizens
    PRO – Nil problem solved
    PRO – Keeps compiler type checking
    PRO – Objects will be simpler than NSNumber. Internal storage will specific to data type.
    CON – Increased memory overhead
    CON – Sacrifices a bit of code portability and compatibility

Looking for a convincing argument in favor of one of these techniques, or one I haven’t thought of if you’ve got one.


UPDATE

I’ve gone ahead and started an open source project (Apache 2.0), into which I’ll be pulling a number of our internal classes as I have time. It currently includes object wrappers for some of the more common native data types (BOOL, CGFloat, NSInteger, NSUInteger). We chose to do this because it upgrades these data types to first class citizens with strict typing. Maybe you disagree with this approach, but it has worked well for us, so feel free to use it if you want.

I’m adding other classes we’ve found uses for, including a disk-backed LRU cache, a “Pair” object, a low memory release pool, etc.

Enjoy
github – Zoosk/ZSFoundation

  • 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-19T04:48:43+00:00Added an answer on May 19, 2026 at 4:48 am

    The most common convention for representing the idea of nil as an NSInteger is to use the NSNotFound value. This is, in fact, equal to NSIntegerMax, though it tends to be more obvious to the reader that this is a sentinel value representing the lack of a number. There are many cases where this is used throughout Cocoa. One common case is as the location field of an NSRange as a return value from -rangeOfString: et al.

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

Sidebar

Related Questions

No related questions found

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.