-
Type Safety - Data TypesiOS/π Swift 2020. 11. 3. 01:41
μ€μννΈμ 3κ°μ§ νΉμ§ : Safe(μμ μ±) , Fast(μ μμ±) , Expressive(ννμ±)
Swiftλ νμ μμ μ±μ 보μ₯νκΈ° μν΄ μλ£νμ μ격νκ² κ΅¬λΆν©λλ€.
κΈ°λ³Έμ μΌλ‘ μλ£νμ μ΄λ¦μ΄ λ€λ₯΄λ©΄ λ°°μ λ° μ°μ°μ΄ λΆκ°λ₯ν©λλ€.
/* μ€μνμ κ°μ Intν λ³μμ λ£μ μ μμ΅λλ€ */ var val1: Int = 12.34 // (X) /* κ°μ νμ΄λΌλ λ©λͺ¨λ¦¬ κ³΅κ° ν¬κΈ°κ° λ€λ₯΄λ―λ‘ λΆκ°λ₯ ν©λλ€ */ var val2: Int = 12 var val3: Int8 = val2 // (X) Int: 8λ°μ΄νΈ, Int8: 1λ°μ΄νΈ
μ°μ° μμλ κ°μ΄ μ μ€λλ λ¬Έμ λ₯Ό μ»΄νμΌ νμμ λ°©μ§νκΈ° μν΄μ κ°μ μλ£νλΌλ¦¬λ§ μ°μ° ν μ μμ΅λλ€.
var left: Int = 100 var right: Double = 56.78 var result = left * right // (X) κ°μ νλΌλ¦¬λ§ μ°μ°ν μ μμ΅λλ€. /* Type Conversion μ΄μ© */ var result = left * Int(right) // result = 5600 var result = Int(Double(left) * right) // result = 5678
λ.
μ΄μ κΈ: Type Inference - Data Types
'iOS > π Swift' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Parameters - Functions (0) 2020.11.06 guard Statement - Conditional Statements (0) 2020.11.04 Type Inference - Data Types (0) 2020.11.03 3 features of First Class Citizen - Function (0) 2020.11.02 Tuples - Tuples (0) 2020.10.25