0Pricing
Objective-C iOS Development for Legacy & Enterprise Apps · บทเรียน

การทำงานกับ NSString และชนิดข้อมูลของ Foundation

ทำความเข้าใจคลาสหลักของ Foundation ใน Objective-C ได้แก่ NSString, NSArray และ NSDictionary เพื่อจัดการข้อความและคอลเลกชันในแอป iOS รุ่นเก่า

การทำงานกับ NSString และชนิดข้อมูลของ Foundation เป็นบทเรียน Objective-C iOS Development for Legacy & Enterprise Apps ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Objective-C iOS Development for Legacy & Enterprise Apps และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Objective-C iOS Development for Legacy & Enterprise Apps มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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.

คำถามที่พบบ่อย

บทเรียน “การทำงานกับ NSString และชนิดข้อมูลของ Foundation” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การทำงานกับ NSString และชนิดข้อมูลของ Foundation” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Objective-C iOS Development for Legacy & Enterprise Apps ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Objective-C iOS Development for Legacy & Enterprise Apps มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การทำงานกับ NSString และชนิดข้อมูลของ Foundation”

ทำความเข้าใจคลาสหลักของ Foundation ใน Objective-C ได้แก่ NSString, NSArray และ NSDictionary เพื่อจัดการข้อความและคอลเลกชันในแอป iOS รุ่นเก่า คุณปฏิบัติ Objective-C iOS Development for Legacy & Enterprise Apps ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Objective-C iOS Development for Legacy & Enterprise Apps หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Objective-C iOS Development for Legacy & Enterprise Apps บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การทำงานกับ NSString และชนิดข้อมูลของ Foundation” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Objective-C iOS Development for Legacy & Enterprise Apps นี้ได้ไหม

ได้ บทเรียน Objective-C iOS Development for Legacy & Enterprise Apps ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. บทนำสู่ Objective-C
  2. ไวยากรณ์และชนิดข้อมูลพื้นฐาน
  3. การตั้งค่า Xcode สำหรับ Objective-C
  4. การทำงานกับ NSString และชนิดข้อมูลของ Foundation
← กลับไปที่ Objective-C iOS Development for Legacy & Enterprise Apps