Working with NSString and Foundation Types
Master Objective-C's core Foundation classes — NSString, NSArray, and NSDictionary — to handle text and collections in legacy iOS apps.
Working with NSString and Foundation Types is a free Objective-C iOS Development for Legacy & Enterprise Apps lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Objective-C iOS Development for Legacy & Enterprise Apps learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Foundation Framework
Beyond primitives, Objective-C leans on the Foundation framework for rich objects — most often NSString, NSArray, and NSDictionary.
Creating NSStrings
The @ literal builds an NSString — a full object with many helper methods, unlike a bare C string.
NSString *name = @"Ada Lovelace";
NSLog(@"Name: %@", name);Common String Methods
NSString ships with handy methods: length, uppercaseString, stringByAppendingString:, and hasPrefix:.
NSString *greeting = [@"Hello, " stringByAppendingString:name];
NSUInteger len = greeting.length;Formatting Strings
Build dynamic text with stringWithFormat:. The %@ token prints any object.
int score = 42;
NSString *msg = [NSString stringWithFormat:@"%@ scored %d", name, score];Mutable Strings
NSString is immutable, so to edit text in place reach for NSMutableString.
NSMutableString *buffer = [NSMutableString stringWithString:@"Hi"];
[buffer appendString:@" there"];NSArray Basics
NSArray is an ordered, immutable list created with the @[] literal, indexed from zero.
NSArray *colors = @[@"red", @"green", @"blue"];
NSString *first = colors[0];
NSUInteger count = colors.count;NSMutableArray
When the list changes at runtime, use NSMutableArray with addObject: and removeObject:.
NSMutableArray *items = [NSMutableArray array];
[items addObject:@"apple"];
[items removeObjectAtIndex:0];NSDictionary Basics
NSDictionary stores key-value pairs, built with the @{} literal and read by key.
NSDictionary *user = @{@"name": @"Ada", @"age": @36};
NSString *n = user[@"name"];NSNumber Boxing
Collections hold objects, not primitives, so wrap numbers in NSNumber with @, then unbox via intValue.
NSNumber *boxed = @42;
int raw = [boxed intValue];Iterating Collections
Walk any collection cleanly with Objective-C's fast enumeration for-in loop.
for (NSString *color in colors) {
NSLog(@"%@", color);
}Why Foundation Matters
Nearly every legacy iOS API takes or returns Foundation types, so fluency here is essential before touching UIKit or networking.
Quick Check
Test your Foundation knowledge.
Recap
Recap: NSString (and mutable variant) for text, stringWithFormat for dynamic strings, NSArray and NSDictionary for collections, and NSNumber to box primitives.
Frequently asked questions
Is the “Working with NSString and Foundation Types” lesson free?
Yes — the full text of “Working with NSString and Foundation Types” is free to read here on the web, and the Objective-C iOS Development for Legacy & Enterprise Apps course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Objective-C iOS Development for Legacy & Enterprise Apps course, upgrade to CoddyKit PRO.
What will I learn in “Working with NSString and Foundation Types”?
Master Objective-C's core Foundation classes — NSString, NSArray, and NSDictionary — to handle text and collections in legacy iOS apps. You practise Objective-C iOS Development for Legacy & Enterprise Apps with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Objective-C iOS Development for Legacy & Enterprise Apps?
No prior experience is required. Objective-C iOS Development for Legacy & Enterprise Apps on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Working with NSString and Foundation Types” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Objective-C iOS Development for Legacy & Enterprise Apps lesson?
Yes. Every Objective-C iOS Development for Legacy & Enterprise Apps lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Objective-C
- Basic Syntax and Data Types
- Setting Up Xcode for Objective-C
- Working with NSString and Foundation Types