100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Objective-C Data Types

Objective-C's primitive types, Foundation typedefs like BOOL and NSInteger, and object types accessed through pointers.

FoundationsBeginner9 min readJul 10, 2026
Analogies

Objective-C Data Types

Objective-C provides all of C's primitive types, int, float, double, char, plus its own Foundation-defined types layered on top, including BOOL for boolean values (YES or NO), NSInteger and NSUInteger as platform-width-safe integer typedefs, and CGFloat for floating-point values that automatically match the platform's native float width. Object types, by contrast, are always accessed through pointers to classes such as NSString, NSNumber, and NSArray.

🏏

Cricket analogy: Like a scoreboard needing both a simple 'out or not out' flag (BOOL) and a precise run count (NSInteger) to describe an innings fully, Objective-C needs both boolean and integer types to describe program state fully.

Primitive and Foundation Types

NSInteger and NSUInteger are typedef'd to match pointer width, 32-bit on older architectures and 64-bit on modern ones, which avoids the overflow and truncation bugs that plague code hard-coded to int or long, and CGFloat similarly resolves to float on 32-bit systems and double on 64-bit systems. BOOL, meanwhile, is technically a signed char with only YES (1) and NO (0) as its conventional values, so comparing a BOOL directly against an arbitrary nonzero value can produce surprising results.

🏏

Cricket analogy: Like a stadium's electronic scoreboard automatically switching from a 3-digit display to a 4-digit display once a total like 999 is threatened, so it never truncates the real score, NSInteger automatically resizes to match the platform's pointer width so it never overflows.

Object Types and id

Foundation classes such as NSString, NSNumber, NSArray, and NSDictionary provide the object-oriented equivalents of C's primitives, strings, and arrays, and they are typically created with literal syntax like @"hello", @42, or @[obj1, obj2] for convenience. The id type is Objective-C's universal object pointer, it can hold a reference to an instance of any class without a cast, enabling the dynamic, duck-typed style of programming where the actual class only matters when a specific message is sent, and nil is Objective-C's safe null object pointer, on which sending any message is a harmless no-op that simply returns 0 or nil.

🏏

Cricket analogy: Like a franchise auction paddle (id) that can represent any player, batsman, bowler, or all-rounder, until the team actually calls them up to bat or bowl, id can point to any object until a specific message reveals its role.

objectivec
#import <Foundation/Foundation.h>

int main(void) {
    @autoreleasepool {
        BOOL isReady = YES;
        NSInteger score = 97;
        CGFloat average = 88.5;
        NSString *player = @"Kohli";
        NSNumber *wrapped = @(score);
        NSArray *scores = @[@88, @92, @97];

        NSLog(@"%@ scored %ld (ready: %@, avg: %.1f)",
              player, (long)score, isReady ? @"YES" : @"NO", average);
        NSLog(@"Wrapped: %@ Scores: %@", wrapped, scores);
    }
    return 0;
}

NSInteger is not a distinct class but a typedef, on 64-bit platforms it resolves to long, and on 32-bit platforms to int, so its actual size can differ across architectures even though your source code looks identical, which is precisely why it's preferred over hardcoding int for values like array counts or loop indices.

Never compare two NSString objects with ==; that operator compares pointer identity, not string contents, so two strings holding the same text can still fail an == check if they're different object instances. Always use [string isEqualToString:other] to compare the actual characters.

  • Objective-C provides C's primitives (int, float, char) plus Foundation typedefs like BOOL, NSInteger, NSUInteger, and CGFloat.
  • BOOL is a signed char with conventional values YES (1) and NO (0).
  • NSInteger and NSUInteger match pointer width, avoiding overflow issues tied to fixed 32-bit types.
  • CGFloat resolves to float on 32-bit systems and double on 64-bit systems.
  • Object types (NSString, NSNumber, NSArray, NSDictionary) are accessed via pointers and often built with @-literal syntax.
  • id is a universal object pointer type; nil is Objective-C's safe null object pointer.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#ObjectiveCStudyNotes#ObjectiveCDataTypes#Objective#Data#Types#Primitive#StudyNotes#SkillVeris#ExamPrep