[카테고리:] 미분류

  • Swift 4에서 Swift 5로 변경된 모든 주요사항

    Swift 5는 2019년 3월에 출시된 Swift 언어의 중요한 이정표로, ABI 안정성 달성과 함께 다양한 새로운 기능과 개선사항을 도입했습니다[1].

    1. ABI 안정성 (ABI Stability) 달성

    Swift 5의 가장 중요한 변화는 ABI 안정성의 달성입니다[1][2]. ABI(Application Binary Interface)는 바이너리 레벨에서의 인터페이스를 의미하며, 이제 Swift 라이브러리가 macOS, iOS, watchOS, tvOS의 모든 현재 및 미래 버전에 포함됩니다[1][3].

    ABI 안정성의 이점

    • 앱 크기 감소: 더 이상 Swift 표준 라이브러리를 앱에 포함시킬 필요가 없어 앱 크기가 작아집니다[1][2]
    • 바이너리 호환성: 서로 다른 Swift 버전으로 컴파일된 앱과 라이브러리 간의 호환성이 보장됩니다[2][3]
    • 빌드 시간 단축: 앱 개발과 빌드가 더 쉬워집니다[1]

    2. 문자열(String) 시스템 개선

    UTF-8 인코딩으로 전환

    Swift 5에서는 문자열의 기본 인코딩이 UTF-16에서 UTF-8로 변경되었습니다[1][4]. 이 변화는 더 빠른 코드 실행을 가능하게 하면서도 Objective-C와의 상호 운용성을 유지합니다[1][4].

    Raw String Literals 지원

    원시 문자열 리터럴 기능이 추가되어 이스케이프 시퀀스를 처리하지 않는 문자열을 생성할 수 있습니다[1][5][6].

    // Swift 4.2
    let message = "Insert this code: \\(1 + 2)"
    
    // Swift 5 - Raw String Literals
    let rawMessage = #"Insert this code: \(1 + 2)"#

    향상된 문자열 인터폴레이션

    문자열 인터폴레이션이 개선되어 데이터로부터 텍스트를 구성하는 데 더 많은 유연성을 제공합니다[7][8].

    3. 새로운 데이터 타입 추가

    Result 타입

    Result 타입이 표준 라이브러리에 공식적으로 추가되어 에러 처리가 개선되었습니다[1][7][9]. Result는 성공과 실패를 모두 표현할 수 있는 열거형입니다[9][6].

    @frozen enum Result<Success, Failure> where Failure : Error {
        case success(Success)
        case failure(Failure)
    }

    SIMD 벡터 타입

    SIMD(Single Instruction, Multiple Data) 벡터 타입이 라이브러리에 추가되어 대부분의 프로세서에서 지원하는 SIMD 타입에 대한 연산을 제공합니다[1][7][10].

    4. 동적 호출 가능 타입 (@dynamicCallable)

    Swift 5에서는 @dynamicCallable 속성이 도입되어 JavaScript, Python, Ruby 등의 언어와의 상호 운용성이 향상되었습니다[1][11][12]. 이를 통해 구조체, 클래스, 열거형을 함수처럼 호출할 수 있습니다[12][13].

    @dynamicCallable
    struct DynamicMultiplier {
        func dynamicallyCall(withArguments args: [Int]) -> Int {
            return args.reduce(1, *)
        }
    }
    
    let multiplier = DynamicMultiplier()
    multiplier(2, 3, 4, 5) // 120

    5. 메모리 안전성 강화

    Swift 5에서는 독점적 메모리 접근(Exclusive Access to Memory)이 릴리스 빌드에서도 기본적으로 강제됩니다[1][14][15]. 이전 버전에서는 디버그 빌드에서만 활성화되었습니다[14][15].

    메모리 접근 제어

    • 읽기 접근쓰기 접근 구분[14][15]
    • 즉시 접근장기 접근 관리[14][15]
    • 동시 읽기/쓰기 또는 동시 쓰기 작업을 제한하여 메모리 안전성 보장[14][15]

    6. 표준 라이브러리 개선사항

    Dictionary와 Set 성능 향상

    Dictionary와 Set의 성능이 개선되었습니다[1][7].

    compactMapValues 메서드 추가

    Dictionary에 compactMapValues 메서드가 추가되어 값들을 필터링할 수 있습니다[7][6].

    let dict: [String : Int?] = ["a": 1, "b": 2, "c": nil, "d": 4]
    print(dict.compactMapValues { $0 ?? nil })
    // ["a": 1, "b": 2, "d": 4]

    기타 표준 라이브러리 변경사항

    • DictionaryLiteral을 KeyValuePairs로 이름 변경[7]
    • Never 타입이 Equatable과 Hashable을 준수[7]
    • BinaryInteger에 isMultiple 추가[7]
    • Unicode.Scalar에 Unicode 속성 추가[1][7]
    • Range 타입에 Codable 준수 추가[7]

    7. 컴파일러 및 언어 개선사항

    메서드 이름 변경

    일부 메서드 이름이 변경되었습니다[16]:

    • index(of:)firstIndex(of:)로 변경[16]
    • index(where:)firstIndex(where:)로 변경[16]

    @autoclosure 매개변수 전달 개선

    @autoclosure 매개변수를 올바르게 전달하기 위해 ()를 추가하는 컴파일러 오류와 수정 제안이 개선되었습니다[16].

    중첩된 옵셔널 처리

    SE-0230에 따라 중첩된 옵셔널이 평면화되어 try? 표현식의 처리가 개선되었습니다[16].

    8. Swift Package Manager 개선

    Swift Package Manager에 다음과 같은 새로운 기능이 추가되었습니다[1]:

    • 타겟별 빌드 설정
    • 의존성 미러링
    • 커스텀 배포 타겟
    • 코드 커버리지 데이터 생성 기능
    • swift run 명령어가 실행 파일을 빌드하지 않고도 REPL에서 라이브러리를 가져올 수 있는 기능[1]

    9. SDK 호환성 변경사항

    Swift 4.2와 5 모드 사이의 SDK 소스 호환성 변경사항은 최소한이며, API의 정확성을 향상시키기 위해 필요한 변경사항들입니다[16]:

    • AppKit의 일부 APINSBindingSelectionMarker 대신 Any 또는 AnyObject를 반환하도록 변경[16]
    • AVFoundation, CloudKit, GameKit의 일부 속성의 반환 타입이 nullable로 변경[16]

    10. 마이그레이션 도구

    Xcode 10.2에는 Swift 5로의 마이그레이션을 돕는 Swift Migrator 도구가 포함되어 있어 대부분의 기계적인 변경사항을 자동으로 처리합니다[16][17]. 마이그레이션은 타겟별로 수행할 수 있으며, Swift 4, 4.2, 5 타겟이 공존하고 함께 링크될 수 있습니다[16][17].

    Swift 5는 언어의 성숙도를 보여주는 중요한 릴리스로, ABI 안정성 달성을 통해 Swift 생태계의 발전을 위한 견고한 기반을 마련했습니다[1][2].

    출처
    [1] What’s new in Apple’s Swift 5 language https://www.infoworld.com/article/3385023/whats-new-in-apples-swift-5-language.html
    [2] [Swift] ABI stability란? – 토미의 개발노트 https://jusung.github.io/ABI-Stability/
    [3] ABI Stability and More – Swift.org https://swift.org/blog/abi-stability-and-more/
    [4] UTF-8 String https://www.swift.org/blog/utf8-string/
    [5] Swift 5: Raw String Literals https://mjtsai.com/blog/2018/12/28/swift-5-raw-string-literals/
    [6] Swift 5에서는 뭐가 바뀌었을까? – SEORENN – 티스토리 https://seorenn.tistory.com/9
    [7] Swift 5 Officially Released, Here’s Whats New – Appetiser https://appetiser.com.au/blog/swift-5-officially-released-heres-whats-new/
    [8] Swift 5 string interpolation https://ilya.puchka.me/swift5-string-interpolation/
    [9] Swift中的Result 类型的简单介绍 https://blog.csdn.net/zhanglei5415/article/details/124006022
    [10] Using SIMD Vector Types in Swift https://swiftrocks.com/using-simd-vector-types-in-swift.html
    [11] SE-0216: User-defined dynamically callable types – Swift Forums https://forums.swift.org/t/se-0216-user-defined-dynamically-callable-types/13615
    [12] What is @dynamicCallable in Swift? – Stack Overflow https://stackoverflow.com/questions/55412536/what-is-dynamiccallable-in-swift
    [13] [Swift] @dynamicCallable 유용한 예제 모음 – 아기개발자의 성장일기 https://eunjin3786.tistory.com/617
    [14] Exclusivity Enforcement in Swift 5 | by Md. Ibrahim Hassan – Swiftify https://blog.swiftify.com/exclusivity-enforcement-in-release-build-in-swift-5-abd751432035
    [15] Exclusivity Enforcement in Swift 5 https://support.swiftify.com/hc/en-us/articles/360028150991-Exclusivity-Enforcement-in-Swift-5
    [16] Migrating to Swift 5 https://swift.org/migration-guide-swift5/
    [17] Swift.org https://www.swift.org/migration-guide-swift5/
    [18] What is the difference between the swift 5 language mode and the … https://forums.swift.org/t/what-is-the-difference-between-the-swift-5-language-mode-and-the-actual-swift-versions-like-5-5-5-7-etc/72991
    [19] Can I use Swiftify to convert Swift 1/2/3/4/5 code to Swift 6? https://support.swiftify.com/hc/en-us/articles/360026402771-Can-I-use-Swiftify-to-convert-Swift-1-2-3-4-5-code-to-Swift-6
    [20] Swift 5.0: How to migrate your project and frameworks – SwiftLee https://www.avanderlee.com/swift/updating-swift-5/
    [21] What’s New in Swift 5? Top 15 Features to Consider for iOS App Development https://www.technource.com/blog/best-swift-5-features/
    [22] ABI stability – ZeddiOS – 티스토리 https://zeddios.tistory.com/654
    [23] ABI Stability – velog https://velog.io/@wansook0316/ABI-Stability
    [24] How can I create a String from UTF8 in Swift? https://stackoverflow.com/questions/24465475/how-can-i-create-a-string-from-utf8-in-swift
    [25] Static and Dynamic Callable Types in Swift – NSHipster https://nshipster.com/callable/
    [26] Swift 5.0 변경사항 – ZeddiOS – 티스토리 https://zeddios.tistory.com/680
    [27] Swift 5에서 Swift 6의 변경점 https://velog.io/@kimt4580/Swift-5%EC%97%90%EC%84%9C-Swift-6%EC%9D%98-%EB%B3%80%EA%B2%BD%EC%A0%90
    [28] [Swift] Swift5 vs Objective C : 문법적 차이 – Bill Kim’s Life… – 티스토리 https://joycestudios.tistory.com/4
    [29] Swift Package Manager(SPM)를 이용한 라이브러리 사용 방법 https://leviblog.tistory.com/33
    [30] What’s new in Swift 5.6 – 때로는 까칠하게.. – 티스토리 https://kka7.tistory.com/370
    [31] [iOS] – Swift Package Manager 생성 및 배포 :: 콰랑 https://quarang.tistory.com/55
    [32] WWDC 2023 스위프트의 새로운 기능 – 1 https://beanistory.tistory.com/27
    [33] [swift]Migrating swift 4 to swift 5 : 네이버 블로그 https://blog.naver.com/banjak2202/221990242458
    [34] Swift 5.0: How to migrate your project and frameworks https://medium.com/@ajvanderlee/swift-5-0-how-to-migrate-your-project-and-frameworks-2b66418442dd
    [35] Swift 5의 ABI 안정성이 앱 개발에 미치는 영향 – 재능넷 https://www.jaenung.net/tree/1448
    [36] ABI stability may finally come in Swift 5.0 – Packt https://www.packtpub.com/sa-sg/learning/tech-news/abi-stability-may-finally-come-in-swift-5-0
    [37] dynamicCallable – ZeddiOS – 티스토리 https://zeddios.tistory.com/1225
    [38] swift-evolution/proposals/0253-callable.md at main – GitHub https://github.com/apple/swift-evolution/blob/main/proposals/0253-callable.md
    [39] [Swift 공부]기본 데이터 타입 (자료형) #1 – 지푸라기 개발자 – 티스토리 https://noahlogs.tistory.com/11
    [40] 어서와! Swift는 처음이지? – Swift5 & Xcode10 버전 | 프로그래머스 스쿨 https://school.programmers.co.kr/learn/courses/9873/9873-%EC%96%B4%EC%84%9C%EC%99%80-swift%EB%8A%94-%EC%B2%98%EC%9D%8C%EC%9D%B4%EC%A7%80-swift5-xcode10-%EB%B2%84%EC%A0%84