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

Sintassi e tipi di dati di base

Impari la sintassi fondamentale, i tipi di dati primitivi e gli oggetti Objective-C più comuni, come NSString e NSArray.

Sintassi e tipi di dati di base è una lezione Objective-C iOS Development for Legacy & Enterprise Apps gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Objective-C iOS Development for Legacy & Enterprise Apps, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Objective-C iOS Development for Legacy & Enterprise Apps include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Domande Frequenti

La lezione «Sintassi e tipi di dati di base» è gratuita?

Sì — il testo completo di «Sintassi e tipi di dati di base» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Objective-C iOS Development for Legacy & Enterprise Apps, passa a CoddyKit PRO. Il corso Objective-C iOS Development for Legacy & Enterprise Apps include 4 lezioni in totale.

Cosa imparerò in «Sintassi e tipi di dati di base»?

Impari la sintassi fondamentale, i tipi di dati primitivi e gli oggetti Objective-C più comuni, come NSString e NSArray. Eserciti Objective-C iOS Development for Legacy & Enterprise Apps con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Objective-C iOS Development for Legacy & Enterprise Apps?

Non è richiesta alcuna esperienza precedente. Objective-C iOS Development for Legacy & Enterprise Apps su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.

Quanto tempo richiede la lezione «Sintassi e tipi di dati di base»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Objective-C iOS Development for Legacy & Enterprise Apps?

Sì. Ogni lezione Objective-C iOS Development for Legacy & Enterprise Apps include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Introduzione a Objective-C
  2. Sintassi e tipi di dati di base
  3. Configurazione di Xcode per Objective-C
  4. Lavorare con NSString e i tipi Foundation
← Torna a Objective-C iOS Development for Legacy & Enterprise Apps