본문 바로가기

iOS/Swift

(14)
Swift 공식문서 4. Collection Types https://docs.swift.org/swift-book/documentation/the-swift-programming-language/collectiontypes Documentation docs.swift.org Swift 공식 문서 보면서 내 맘대로 정리Swift에서 제공하는 Collection TypeArraySetDictionary모든 Collection 들은 변경 가능하다.var로 선언하면 값을 추가, 삭제, 변경 가능하다. (mutable)let으로 선언하면 추가, 제거, 변경 불가능 하다. (immutable)ArrayArray는 같은 타입의 값들을 순서대로 저장중복된 값이 여러 장소에 존재할 수 있다.빈 Array 생성var someInts = [Int]()Array의 모든 값을 동..
Swift 공식 문서 3. Strings and Characters (2) https://docs.swift.org/swift-book/documentation/the-swift-programming-language/stringsandcharacters Documentation docs.swift.org Swift 공식 문서 보면서 내 맘대로 정리 String Indices문자열의 인덱스와 String.Index 타입String에는 각 Character의 위치를 나타내는 String.Index 타입이 있다.Swift 문자열은 정수 값으로 직접 인덱싱할 수 없다.문자들이 차지하는 메모리 크기가 다를 수 있기 때문에, 특정 위치의 문자를 찾기 위해서는 문자열의 시작 또는 끝에서 부터 유니코드 스칼라를 하나씩 탐색해야 한다. startIndex와 endIndexstartIndex :..
Swift API Design Guidelines https://www.swift.org/documentation/api-design-guidelines/ Swift.orgSwift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns.www.swift.org 최고의 컨벤션Fundamentals사용 지점에서의 명료함(Clarity)이 가장 중요한 목표이다.메서드, 프로퍼티는 한번 정의되지만 반복적으로 사용된다.API를 설계하면 이들을 명확하고 간결하게 만든다.설계를 평가할 때, 선언을 읽는 것 만으로는 불충분하다. 항상 사용성을 검토하여 문맥상 명확하게 이해되는지를 확인해야 한다.Cla..
Swift 공식 문서 3. Strings and Characters (1) https://docs.swift.org/swift-book/documentation/the-swift-programming-language/stringsandcharacters Documentation docs.swift.org  Swift 공식 문서 보면서 내 맘대로 정리 Swift에서 문자열 및 문자 타입은 코드에서 텍스트를 유니코드 호환 방법으로 제공하고 문법적인 부분은 C와 비슷하다.Swift의 String은 Foundation 프레임워크의 NSString이 bridge된 타입이기 때문에 NSString의 메서드를 String에서 캐스팅 없이 사용이 가능하다.String Literals문자열을 여러줄에 쓰고 싶다면 """을 사용"""안의 문장 안에서 가독성을 위해 줄 바꿈 하고 싶지만, 문자열에..
Swift 공식 문서 2. Basic Operator https://docs.swift.org/swift-book/documentation/the-swift-programming-language/basicoperators Documentation docs.swift.org  Swift 공식 문서 보면서 내 맘대로 정리Arithmetic OperatorsSwift의 산술 연산자는 오버플로우를 허용하지 않음. → 런타임 에러 발생오버플로우 연산자를 활용하면 오버플로가 발생했을 때 실행을 제어할 수 있다.Overflow OperatorsSwift에서 정수 상수나 변수를 특정 타입이 담을 수 없는 값으로 설정하면 오류 발생var potentialOverflow = Int16.maxpotentialOverflow += 1 오버플로우가 발생하더라도 사용 가능한 비트 ..
Swift 공식 문서 1. The Basics https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics Documentation docs.swift.orgSwift 공식 문서 보면서 내 맘대로 정리Constant and Variables ( 상수와 변수)상수, 변수를 한 줄에 선언할 수 있다.var x = 0.0, y = 0.0, z = 0.0var red, green, blue : Double변수와 상수의 이름은 유니코드로 선언할 수 있다.let 😍 = "love"print 함수는 separator, terminator를 갖고 이들은 default 값을 다음과 같이 갖는다public func print(_ items: Any..., separat..