Thuta Learning
Swift
BasicProgrammingအခြေခံ

Strings

Swiftသင်ခန်းစာ 820 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Strings ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
  • Nil, error, boundary နဲ့concurrency cases စမ်းနိုင်ရန်
  • Safe, testable Swift code ရေးနိုင်ရန်

ရိုးရိုးလေး ရှင်းပြမယ်

Strings ကို ရိုးရိုးလေးနားလည်မယ်

String က user name, message, title, description, API response text စတာတွေသိမ်းဖို့သုံးပါတယ်။ Swift string မှာ interpolation, prefix/suffix check, uppercase/lowercase, count စတဲ့ useful methods တွေရှိပါတယ်။

Problem → Why → Solution

ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ

String ထဲမှာ quote ပါချင်ရင် escape လုပ်ရနိုင်ပါတယ်။ ဥပမာ "Hello" ။

ဖြစ်လေ့ရှိတဲ့အမှား

Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။

Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်

Strings ကိုsyntax အဖြစ်သာမမြင်ဘဲvalue/reference semantics, mutability, copying, identity, optionality နဲ့lifetime contract အဖြစ်နားလည်ပါ။ Struct/enum value types ကိုdefault စဉ်းစားပြီးclass identity နဲ့shared mutable state ကိုလိုမှသာသုံးပါ။

Mental Model
  1. Typed value
  2. Swift expression / function
  3. Safe result

Strings ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / Pattern

swift
let productName = "Thuta Studio"
let featureCount = 12

let message = "\(productName) includes \(featureCount)+ creative tools."

print(message)
print(message.hasPrefix("Thuta"))
print(productName.uppercased())

Strings ကိုsyntax အဖြစ်သာမမြင်ဘဲvalue/reference semantics, mutability, copying, identity, optionality နဲ့lifetime contract အဖြစ်နားလည်ပါ။ Struct/enum value types ကိုdefault စဉ်းစားပြီးclass identity နဲ့shared mutable state ကိုလိုမှသာသုံးပါ။

Code ကို အဆင့်လိုက်ဖတ်မယ်

  1. Typed valuelet productName = "Thuta Studio"

    String က user name, message, title, description, API response text စတာတွေသိမ်းဖို့သုံးပါတယ်။ Swift string မှာ interpolation, prefix/suffix check, uppercase/lowercase, count စတဲ့ useful methods တွေရှိပါတယ်။

  2. Swift expression / functionprint(message)

    Strings ကိုsyntax အဖြစ်သာမမြင်ဘဲvalue/reference semantics, mutability, copying, identity, optionality နဲ့lifetime contract အဖြစ်နားလည်ပါ။ Struct/enum value types ကိုdefault စဉ်းစားပြီးclass identity နဲ့shared mutable state ကိုလိုမှသာသုံးပါ။

  3. Safe resultprint(productName.uppercased())

    Strings example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

Execution Flow
  1. Typed value
  2. Swift expression / function
  3. Safe result

Success

Strings ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

Failure

String ထဲမှာ quote ပါချင်ရင် escape လုပ်ရနိုင်ပါတယ်။ ဥပမာ "Hello" ။

String က user name, message, title, description, API response text စတာတွေသိမ်းဖို့သုံးပါတယ်။ Swift string မှာ interpolation, prefix/suffix check, uppercase/lowercase, count စတဲ့ useful methods တွေရှိပါတယ်။

swift
let productName = "Thuta Studio"
let featureCount = 12

let message = "\(productName) includes \(featureCount)+ creative tools."

print(message)
print(message.hasPrefix("Thuta"))
print(productName.uppercased())

\(productName) နဲ့ \(featureCount) က variable value တွေကို sentence ထဲသွင်းထားတာပါ။ hasPrefix() က string ရဲ့အစမှာ သတ်မှတ်ထားတဲ့ text ပါ/မပါ စစ်ပါတယ်။

You should see
Thuta Studio includes 12+ creative tools. true THUTA STUDIO

Real-world usage

လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ

Strings example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

Mini challenge

ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ

Strings 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 ကိုခန့်မှန်းပါ
swift
let productName = "Thuta Studio"
let featureCount = 12

let message = "\(productName) includes \(featureCount)+ creative tools."

print(message)
print(message.hasPrefix("Thuta"))
print(productName.uppercased())

ရလဒ်: Strings ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

အရိပ်အမြွက် ကြည့်ရန်

Strings example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

Quick Quiz 1 / 3

Strings ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

ဘယ်အမှားကို အရင်ဆုံးရှောင်သင့်လဲ။

Quick Quiz 3 / 3

Real project မှာ ဘယ်လိုအသုံးချသင့်လဲ။

ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ

  • Typed value → Swift expression / function → Safe result
  • Strings ကိုsyntax အဖြစ်သာမမြင်ဘဲvalue/reference semantics, mutability, copying, identity, optionality နဲ့lifetime contract အဖြစ်နားလည်ပါ။ Struct/enum value types ကိုdefault စဉ်းစားပြီးclass identity နဲ့shared mutable state ကိုလိုမှသာသုံးပါ။
  • String ထဲမှာ quote ပါချင်ရင် escape လုပ်ရနိုင်ပါတယ်။ ဥပမာ "Hello" ။
  • Strings 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

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • String ထဲမှာ quote ပါချင်ရင် escape လုပ်ရနိုင်ပါတယ်။ ဥပမာ "Hello" ။
  • Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
  • Force unwrap သို့unchecked shared mutable state ဖြင့်compiler safety ကိုကျော်ခြင်း။

လက်တွေ့လေ့ကျင့်ခန်း

Strings example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Thuta Studio includes 12+ creative tools. true THUTA STUDIO

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Strings | Thuta Learning