[Grammer] 11 - Type Inference, Type Safety, 12 - Type Conversion, Type Aliases

in swift4 •  6 years ago 
  • Type Inference: 타입을 값을 보고 추론함.
let num = 123 
  • Type Annotation : 타입을 직접 지정함
let num: Int = 123 
  • Type Safety : 안정성을 위해 자료형을 엄격히 구분. 모든 타입간 호환 불가.
    Int+Double / Int8+Int 등 모두 에러. 이러한 계산은 형변환이 필요.

  • Type Conversion : Type(value)

let a = 123
let b = 4.56
let result1 = Double(a) + b // 127.56
let result2 = a + Int(b)    // 127
  • Type Aliases : typealias NewName = TypeName
typealias Coordinate = Double
let lat: Double = 37.497942
let lon: Coordinate = 127.027621
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!