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.
#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
1. What are the conventional values of a BOOL in Objective-C?
2. Why is NSInteger preferred over a hardcoded int for values like array counts?
3. What is the correct way to compare the contents of two NSString objects?
4. What does the id type represent?
5. What happens when you send a message to nil in Objective-C?
Was this page helpful?
You May Also Like
Objective-C Syntax and Variables
How Objective-C extends C syntax with object messaging, and how primitive versus object variables are declared.
What Is Objective-C?
A history and overview of Objective-C, the C-based, Smalltalk-inspired language that powered Apple's platforms for decades.
Your First Objective-C Program
Writing, compiling, and running a first Objective-C 'Hello, World!' program from the terminal.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics