0Pricing
Objective-C iOS Development for Legacy & Enterprise Apps · Lesson

Basic Syntax and Data Types

Learn the fundamental syntax, primitive data types, and common Objective-C objects like NSString and NSArray.

Basic Syntax and Data Types is a free Objective-C iOS Development for Legacy & Enterprise Apps lesson on CoddyKit — lesson 2 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.

Objective-C Basics

Time for the fundamentals: Objective-C's basic syntax and the data types you will work with every day.

Statements End with Semicolons

Like other C-based languages, every Objective-C statement ends with a semicolon. Forget one and Xcode will flag it fast.

Explain Your Code with Comments

Comments are notes the compiler ignores. Use // for a single line and /* */ for multi-line blocks.

Primitive Data Types

Primitive types hold simple values: int, float/double, char, and BOOL (which is YES or NO).

Primitives in Action

Here those primitive types come to life — declared, assigned, and printed with NSLog format specifiers.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
  @autoreleasepool {
    int age = 30;
    float price = 19.99f; // 'f' for float literal
    double pi = 3.14159;
    char initial = 'J';
    BOOL isLoggedIn = YES;

    NSLog(@"Age: %i", age);
    NSLog(@"Price: %.2f", price);
    NSLog(@"Pi: %f", pi);
    NSLog(@"Initial: %c", initial);
    NSLog(@"Logged In: %@", isLoggedIn ? @"YES" : @"NO");
  }
  return 0;
}

Working with Text: NSString

For words and sentences you use the NSString object, not char. NSString is immutable: its contents never change after creation.

NSString Example

Declaring an NSString uses the @ prefix before the literal — a piece of syntax unique to Objective-C.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
  @autoreleasepool {
    NSString *greeting = @"Hello, CoddyKit!";
    NSString *name = @"Alice";
    NSString *message = [NSString stringWithFormat:@"Welcome, %@!", name];

    NSLog(@"Greeting: %@", greeting);
    NSLog(@"Personal Message: %@", message);
  }
  return 0;
}

Collections: NSArray

NSArray stores an ordered list of objects, accessed by zero-based index. It is immutable; use NSMutableArray when you need to change it.

NSArray Example

Create an NSArray with the @[] literal. The older arrayWithObjects form needs a nil terminator.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
  @autoreleasepool {
    // Array literal syntax
    NSArray *fruits = @[@"Apple", @"Banana", @"Cherry"];

    NSLog(@"First fruit: %@", fruits[0]); // Access by index
    NSLog(@"All fruits: %@", fruits);

    // Another way to create (older, but good to know)
    NSArray *colors = [NSArray arrayWithObjects:@"Red", @"Green", @"Blue", nil];
    NSLog(@"Colors: %@", colors);
  }
  return 0;
}

Quick Check on Types

Consider the following Objective-C declarations. Which one correctly defines a boolean variable named isActive and sets it to true?

Recap: Syntax & Data Types

Recap: semicolons end statements, comments document, primitives like int and BOOL hold simple values, and NSString and NSArray handle text and lists.

Frequently asked questions

Is the “Basic Syntax and Data Types” lesson free?

Yes — the full text of “Basic Syntax and Data 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 “Basic Syntax and Data Types”?

Learn the fundamental syntax, primitive data types, and common Objective-C objects like NSString and NSArray. 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Basic Syntax and Data 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

  1. Introduction to Objective-C
  2. Basic Syntax and Data Types
  3. Setting Up Xcode for Objective-C
  4. Working with NSString and Foundation Types
← Back to Objective-C iOS Development for Legacy & Enterprise Apps