Swift က type-safe language ဖြစ်ပါတယ်။ ဆိုလိုတာက variable တစ်ခုမှာ ဘယ် data type သိမ်းမလဲဆိုတာကို compiler က တိတိကျကျသိထားရပါတယ်။ ဒါကြောင့် number ထဲကို text ထည့်တာ၊ text ထဲကို boolean ထည့်တာလို mistake တွေကို စောစောဖမ်းပေးနိုင်ပါတယ်။
Swift မှာ type ကို ကိုယ်တိုင်ရေးနိုင်သလို compiler က တန်ဖိုးကြည့်ပြီး ခန့်မှန်းပေးတဲ့ type inference လည်းရှိပါတယ်။
swift
let name: String = "Nandar" // Explicit type
let age = 24 // Int လို့ compiler ကခန့်မှန်းမယ်
let rating = 4.8 // Double
let isPremiumUser = true // Bool
print("\(name) is \(age) years old.")
print("Rating: \(rating), Premium: \(isPremiumUser)")String ကစာသား၊ Int က ကိန်းပြည့်၊ Double က ဒဿမကိန်း၊ Bool က true/false တန်ဖိုးပါ။ \(...) ကို string interpolation လို့ခေါ်ပြီး string ထဲမှာ variable value ထည့်ပြနိုင်ပါတယ်။
You should see
Nandar is 24 years old. Rating: 4.8, Premium: true