基本構文とデータ型
基本構文、プリミティブデータ型、NSStringやNSArrayなどの一般的なObjective-Cオブジェクトを学びます。
「基本構文とデータ型」はCoddyKit上の無料Objective-C iOS Development for Legacy & Enterprise Appsレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはObjective-C iOS Development for Legacy & Enterprise Apps学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Objective-C iOS Development for Legacy & Enterprise Appsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.
よくある質問
「基本構文とデータ型」レッスンは無料ですか?
はい。「基本構文とデータ型」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Objective-C iOS Development for Legacy & Enterprise Appsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Objective-C iOS Development for Legacy & Enterprise Appsコースには全4レッスンが含まれています。
「基本構文とデータ型」で何を学びますか?
基本構文、プリミティブデータ型、NSStringやNSArrayなどの一般的なObjective-Cオブジェクトを学びます。 ブラウザで直接実行するハンズオンコードでObjective-C iOS Development for Legacy & Enterprise Appsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Objective-C iOS Development for Legacy & Enterprise Appsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのObjective-C iOS Development for Legacy & Enterprise Appsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「基本構文とデータ型」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このObjective-C iOS Development for Legacy & Enterprise Appsレッスンでコードを書いて実行できますか?
はい。すべてのObjective-C iOS Development for Legacy & Enterprise Appsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。