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

Sintaks dan Tipe Data Dasar

Pelajari sintaks dasar, tipe data primitif, dan objek Objective-C umum seperti NSString dan NSArray.

Sintaks dan Tipe Data Dasar adalah pelajaran Objective-C iOS Development for Legacy & Enterprise Apps gratis di CoddyKit. Ini adalah pelajaran 2 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Objective-C iOS Development for Legacy & Enterprise Apps, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Objective-C iOS Development for Legacy & Enterprise Apps mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Sintaks dan Tipe Data Dasar” gratis?

Ya — teks lengkap “Sintaks dan Tipe Data Dasar” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Objective-C iOS Development for Legacy & Enterprise Apps, upgrade ke CoddyKit PRO. Kursus Objective-C iOS Development for Legacy & Enterprise Apps mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Sintaks dan Tipe Data Dasar”?

Pelajari sintaks dasar, tipe data primitif, dan objek Objective-C umum seperti NSString dan NSArray. Kamu berlatih Objective-C iOS Development for Legacy & Enterprise Apps dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Objective-C iOS Development for Legacy & Enterprise Apps?

Tidak diperlukan pengalaman sebelumnya. Objective-C iOS Development for Legacy & Enterprise Apps di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 2 dari 4.

Berapa lama pelajaran “Sintaks dan Tipe Data Dasar” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Objective-C iOS Development for Legacy & Enterprise Apps ini?

Ya. Setiap pelajaran Objective-C iOS Development for Legacy & Enterprise Apps menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Pengantar Objective-C
  2. Sintaks dan Tipe Data Dasar
  3. Menyiapkan Xcode untuk Objective-C
  4. Bekerja dengan NSString dan Tipe Foundation
← Kembali ke Objective-C iOS Development for Legacy & Enterprise Apps