ရိုးရိုးလေး ရှင်းပြမယ်
Arrays ကို ရိုးရိုးလေးနားလည်မယ်
Array က တူညီတဲ့ type ရှိတဲ့ data တွေကို အစဉ်လိုက်သိမ်းတဲ့ collection ပါ။ Product list, menu items, todo tasks, lesson titles စတာတွေကို array နဲ့သိမ်းနိုင်ပါတယ်။ Array index က 0 ကနေစပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Array မှာ 3 items ပဲရှိရင် lessons[3] က fourth item ဖြစ်ပါတယ်။ lessons[4] ဆို index out of range ဖြစ်နိုင်ပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Arrays ကိုsyntax အဖြစ်သာမမြင်ဘဲvalue/reference semantics, mutability, copying, identity, optionality နဲ့lifetime contract အဖြစ်နားလည်ပါ။ Struct/enum value types ကိုdefault စဉ်းစားပြီးclass identity နဲ့shared mutable state ကိုလိုမှသာသုံးပါ။
- Typed value
- Swift expression / function
- Safe result
Arrays ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
var lessons = ["Intro", "Variables", "Arrays"]
print(lessons[0])
lessons.append("Functions")
for lesson in lessons {
print("Lesson: \(lesson)")
}
print("Total lessons: \(lessons.count)")Arrays ကိုsyntax အဖြစ်သာမမြင်ဘဲvalue/reference semantics, mutability, copying, identity, optionality နဲ့lifetime contract အဖြစ်နားလည်ပါ။ Struct/enum value types ကိုdefault စဉ်းစားပြီးclass identity နဲ့shared mutable state ကိုလိုမှသာသုံးပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Typed value
var lessons = ["Intro", "Variables", "Arrays"]Array က တူညီတဲ့ type ရှိတဲ့ data တွေကို အစဉ်လိုက်သိမ်းတဲ့ collection ပါ။ Product list, menu items, todo tasks, lesson titles စတာတွေကို array နဲ့သိမ်းနိုင်ပါတယ်။ Array index က 0 ကနေစပါတယ်။
- Swift expression / function
for lesson in lessons {Arrays ကိုsyntax အဖြစ်သာမမြင်ဘဲvalue/reference semantics, mutability, copying, identity, optionality နဲ့lifetime contract အဖြစ်နားလည်ပါ။ Struct/enum value types ကိုdefault စဉ်းစားပြီးclass identity နဲ့shared mutable state ကိုလိုမှသာသုံးပါ။
- Safe result
print("Total lessons: \(lessons.count)")Arrays example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
- Typed value
- Swift expression / function
- Safe result
Success
Arrays ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
Failure
Array မှာ 3 items ပဲရှိရင် lessons[3] က fourth item ဖြစ်ပါတယ်။ lessons[4] ဆို index out of range ဖြစ်နိုင်ပါတယ်။
Array က တူညီတဲ့ type ရှိတဲ့ data တွေကို အစဉ်လိုက်သိမ်းတဲ့ collection ပါ။ Product list, menu items, todo tasks, lesson titles စတာတွေကို array နဲ့သိမ်းနိုင်ပါတယ်။ Array index က 0 ကနေစပါတယ်။
var lessons = ["Intro", "Variables", "Arrays"]
print(lessons[0])
lessons.append("Functions")
for lesson in lessons {
print("Lesson: \(lesson)")
}
print("Total lessons: \(lessons.count)")lessons[0] က ပထမဆုံး item ကိုယူတာပါ။ append() က item အသစ်ထည့်ပြီး for-in loop က array ထဲက item တစ်ခုချင်းစီကို လှည့်ထုတ်ပြပါတယ်။
Intro Lesson: Intro Lesson: Variables Lesson: Arrays Lesson: Functions Total lessons: 4Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Arrays example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Arrays example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
var lessons = ["Intro", "Variables", "Arrays"]
print(lessons[0])
lessons.append("Functions")
for lesson in lessons {
print("Lesson: \(lesson)")
}
print("Total lessons: \(lessons.count)")ရလဒ်: Arrays ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Arrays example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Typed value → Swift expression / function → Safe result
- Arrays ကိုsyntax အဖြစ်သာမမြင်ဘဲvalue/reference semantics, mutability, copying, identity, optionality နဲ့lifetime contract အဖြစ်နားလည်ပါ။ Struct/enum value types ကိုdefault စဉ်းစားပြီးclass identity နဲ့shared mutable state ကိုလိုမှသာသုံးပါ။
- Array မှာ 3 items ပဲရှိရင် lessons[3] က fourth item ဖြစ်ပါတယ်။ lessons[4] ဆို index out of range ဖြစ်နိုင်ပါတယ်။
- Arrays example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
The Swift Programming Language — Swift.org