스위프트
[Swift] Swift 공식문서 정리 - 5(옵셔널 체이닝)
옵셔널이란? 옵셔널이란 nil을 사용할 수 있는 Type을 옵셔널 타입이라고 부르며, nil을 가질 수 있는 값은 옵셔널 타입이다. 옵셔널 체이닝(Optional Chaining) class Person { var residence: Residence? } if let roomCount = john.residence?.numberOfRooms { print("John's residence has \(roomCount) room(s).") } else { print("Unable to retrieve the number of rooms.") } // Prints "Unable to retrieve the number of rooms." 강제 언래핑(Forced Wrapping) var name: Strin..
[Swift] Swift 공식문서 정리 - 4(열거형)
열거형이란 ? - 같은 주제로 연관된 데이터들을 멤버로 구성하여 나타내는 자료형 열거형의 선언 enum CompassPoint { case north case south case east case west } var directionToHead = CompassPoint.west // 이후엔 생략 가능 directionToHead = .east Switch 구문에서 열거형의 사용 directionToHead = .south switch directionToHead { case .north: print("Lots of planets have a north") case .south: print("Watch out for penguins") case .east: print("Where the sun rises..