Swift 4에서 Swift 6까지의 주요 변경사항 완전 정리

Swift 4에서 Swift 6로의 업그레이드는 단순한 버전 업데이트가 아닌 언어의 근본적인 발전을 의미합니다. 특히 동시성 프로그래밍과 데이터 레이스 안전성 측면에서 혁신적인 변화가 있었습니다.

Swift 5.0 (2019년 3월) – ABI 안정성 달성

핵심 변화

  • ABI 안정성 달성: Swift 런타임이 모든 현재 및 미래 버전의 macOS, iOS, tvOS, watchOS에 통합되어 앱 크기가 줄어들고 개발이 용이해짐 [1]
  • String 재구현: UTF-8 인코딩으로 재구현되어 더 빠른 코드 실행 가능 [1]
  • 향상된 String 보간: 데이터로부터 텍스트를 구성하는 더 유연한 방법 제공 [1]

표준 라이브러리 업데이트

  • Result 타입과 SIMD 벡터 타입이 표준 라이브러리에 추가 [1]
  • DictionarySet의 성능 개선 [1]
  • compactMapValues 메서드를 Dictionary에 추가 [1]
  • DictionaryLiteral 타입을 KeyValuePairs로 이름 변경 [1]

Swift 5.1 (2019년 9월) – 모듈 안정성

주요 기능

  • 모듈 안정성: 바이너리 프레임워크를 생성하고 다양한 컴파일러 버전과 호환 가능 [2]
  • Property Wrappers: 보일러플레이트 코드를 크게 줄이고 앱 성능을 최적화 [2]
  • Opaque Result Types: 리턴 타입을 더 유연하게 처리 [2]
  • Key Path Member Lookup: 키 패스를 통한 멤버 접근 개선 [2]

Swift 5.2 (2020년 3월) – 진단 개선

개선사항

  • 향상된 오류 메시지: 특히 SwiftUI에서 더 정확한 오류 설명과 위치 제공 [3]
  • Key Path Expressions as Functions: 키 패스 표현식을 함수로 사용 가능 [3]
  • Subscripts with Default Arguments: 기본 인수를 가진 서브스크립트 지원 [3]
  • 호출 가능한 타입: 타입을 함수처럼 호출 가능 [3]

Swift 5.3 (2020년 9월) – 다중 패턴 지원

새로운 기능

  • 다중 패턴 catch 절: 하나의 catch 절에서 여러 패턴 지정 가능 [4]
  • Enum의 Comparable 준수 자동 합성: enum 타입이 자동으로 Comparable 프로토콜 준수 [4]
  • 확장된 implicit self: 값 타입에서 참조 사이클 위험이 없는 경우 implicit self 사용 확대 [4]

Swift 5.4 (2021년 4월) – Result Builders

핵심 변화

  • 향상된 implicit member 구문: 단일 정적 멤버뿐만 아니라 체인된 표현식 지원 [5]
  • 다중 variadic 매개변수: 함수, 서브스크립트, 이니셜라이저에서 여러 variadic 매개변수 사용 가능 [5]
  • Result Builders: SwiftUI의 뷰 생성 시스템을 지원하는 공식 기능 [5]
  • 로컬 함수 오버로딩: 로컬 함수에서 오버로딩 지원 [5]

Swift 5.5 (2021년 9월) – 동시성 혁명

동시성 프로그래밍 도입

  • async/await: 비동기 프로그래밍의 혁신적 변화, 콜백 지옥 해결 [6][7][8]
  • Actor 모델: 데이터 레이스 없이 안전한 동시성 프로그래밍 지원 [9]
  • @MainActor: UI 업데이트를 위한 메인 스레드 자동 실행 [10]
  • Sendable 프로토콜: 스레드 간 안전한 데이터 전송 보장 [11]

기존 문제 해결

GCD의 주요 문제점들을 해결 [8]:

  • Thread explosion 방지
  • Priority inversion 개선
  • Execution hierarchy 부족 문제 해결

Swift 5.6 (2022년 3월) – Existential Any

주요 변화

  • any 키워드 도입: Existential 타입 명시적 표현, Swift 6에서 필수가 될 예정 [12]
  • 성능 최적화: 프로토콜 기반 접근 방식의 성능 영향 최소화 [12]

Swift 5.7 (2022년 9월) – Opaque Parameters

새로운 기능

  • Opaque Parameters: 제네릭 보일러플레이트 없이 제네릭 매개변수 지정 가능 [13]
  • 함수 매개변수에서 opaque 타입 사용: 더 간결한 제네릭 함수 작성 [13]

Swift 5.8 (2023년 3월) – RegexBuilder

정규표현식 지원

  • RegexBuilder: 동적 정규표현식 패턴 생성 지원 [14]
  • 재사용 가능한 Regex 패턴: 가변 문자열 구성요소를 포함한 패턴 생성 가능 [14]

Swift 5.9 (2023년 9월) – 매크로 시스템

혁신적 기능

  • 매크로 시스템: SwiftSyntax 라이브러리를 사용한 코드 생성 [15]
  • Parameter Packs: 임의의 수의 타입을 다루는 제네릭 타입과 함수 정의 [15]
  • 소유권 기반 메모리 관리: 향상된 메모리 관리 기능 [15]
  • C++ 상호 운용성: 제한적인 형태의 C++ 코드와의 상호 운용 [15]

매크로 종류

  • Freestanding macros: # 접두사, 독립적으로 사용 [15]
  • Attached macros: @ 접두사, 선언을 수정 [15]

Swift 6.0 (2024년 9월) – 데이터 레이스 안전성

가장 중요한 변화: 완전한 동시성 검사

Swift 6의 핵심은 컴파일 타임에 데이터 레이스를 완전히 방지하는 것입니다 [16][17][18].

엄격한 동시성 규칙 강화

  • 컴파일 타임 데이터 레이스 감지: 런타임 전에 동시성 문제 발견 [19]
  • 엄격한 격리 규칙: 스레드 간 데이터 안전한 접근 보장 [19]
  • 향상된 구조화된 동시성: async/await와 Task를 사용한 개선된 작업 관리 [19]
  • 더 강력한 Actor 모델: 공유 상태 관리에서 더욱 강력해진 Actor [19]

Sendable 프로토콜 강화

Swift 6에서는 Sendable 준수가 더욱 엄격해짐 [20][11]:

  • 동시 컨텍스트에서 값을 안전하게 공유할 수 있는 스레드 안전 타입 명시
  • @Sendable 클로저는 동기화되지 않은 공유 상태 수정 불가

Actor 격리 강화

  • isolated 키워드: 함수 매개변수에만 사용 가능, Actor 상태에 await 없이 접근 [21]
  • nonisolated 키워드: Actor의 가변 상태에 의존하지 않는 속성과 메서드 표시 [21]
  • @MainActor 개선: UI 관련 코드의 메인 스레드 실행 자동화 [10]

글로벌 Actor 시스템

Swift 6에서는 글로벌 Actor를 통해 전역 상태와 함수가 Actor 격리의 혜택을 받을 수 있음 [22]:

  • 전역 변수의 데이터 레이스 제거
  • 메인 스레드나 UI 스레드에서만 실행되어야 하는 코드 모델링

마이그레이션 전략

점진적 마이그레이션

Swift 6는 모듈별 점진적 마이그레이션을 지원합니다 [18][23]:

  1. Complete Concurrency Checking 활성화: Swift 5 모드에서 경고로 확인
  2. 각 타겟별 경고 해결: 데이터 격리 실패 경고 모두 수정
  3. Swift 6 모드 활성화: 타겟별로 순차적으로 활성화
  4. 컴파일러 진단 활용: 수정이 필요한 코드 위치 안내

Xcode 설정

SWIFT_STRICT_CONCURRENCY = complete

SwiftPM 설정

.enableUpcomingFeature("StrictConcurrency")

주요 Breaking Changes 요약

버전주요 Breaking Change영향도
5.0ABI 안정성, String 재구현높음
5.5async/await, Actor 도입매우 높음
5.6any 키워드 도입중간
6.0엄격한 동시성 검사 강제매우 높음

Swift 4.2에서 Swift 6로의 전환은 특히 동시성 프로그래밍 패러다임의 완전한 변화를 의미합니다. 기존의 GCD 기반 코드를 async/await와 Actor 기반으로 전환하고, 모든 데이터 레이스 가능성을 컴파일 타임에 제거해야 하는 대규모 작업이 필요합니다 [24][16][25].

출처
[1] Swift 5 Officially Released, Here’s Whats New – Appetiser https://appetiser.com.au/blog/swift-5-officially-released-heres-whats-new/
[2] What is New in Swift 5.1 Update? https://www.cmarix.com/blog/key-new-features-and-value-additions-brought-by-swift-5-1-update/
[3] What’s New in Swift 5.2 – Kodeco https://www.kodeco.com/9224115-what-s-new-in-swift-5-2
[4] Swift 5.3 Brings New Language Features, Better Developer Experience, and Improved Performance https://www.infoq.com/news/2020/09/swift-5-3-released/
[5] What’s new in Swift 5.4? – Ramani Hitesh – LinkedIn https://www.linkedin.com/pulse/whats-new-swift-54-ramani-hitesh
[6] [Swift Concurrency] async & await 문법 – velog https://velog.io/@jeunghun2/Swift-async-await
[7] [Swift Concurrency] Async/await – ZeddiOS – 티스토리 https://zeddios.tistory.com/1230
[8] [Swift 5.5] GCD의 문제? Swift 5.5 Concurrency model 특징과 async … https://dev-with-precious-dreams.tistory.com/206
[9] Swift 5.5 – async & await – iOYES – 티스토리 https://green1229.tistory.com/177
[10] @MainActor in Swift — Detailed walkthrough https://itnext.io/mainactor-in-swift-detailed-walkthrough-94044c83118b?gi=587a3b85551d
[11] Understanding Sendable in Swift – Wesley de Groot https://wesleydegroot.nl/blog/Sendable-in-Swift
[12] Is existential any a performance problem in Swift? https://augmentedcode.io/2022/04/04/is-existential-any-a-performance-problem-in-swift/
[13] swift-evolution/proposals/0341-opaque-parameters.md at main https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md
[14] Creating Reusable Swift Regex Patterns with Variable Subcomponents https://www.youtube.com/watch?v=oFcB3ofOPfc
[15] Swift 5.9 Brings a Macro System and C++ Interoperability – InfoQ https://www.infoq.com/news/2023/10/swift-5-9-released/
[16] Swift 6: Key Changes and How to Migrate Your Projects https://blog.nashtechglobal.com/swift-6-key-changes-and-how-to-migrate-your-projects/
[17] Data Race Safety | Documentation – Swift.org https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/dataracesafety/
[18] Swift.org https://www.swift.org/documentation/concurrency/
[19] 🚀 Swift 6 Enhanced Concurrency Model https://www.linkedin.com/pulse/swift-6-enhanced-concurrency-model-hardik-kothari-1aake
[20] Swift Concurrency 6편 – @Sendable 과 Data Race Safety는? – velog https://velog.io/@little_tail/SwiftConcurrency-6%ED%8E%B8
[21] Swift actor isolated vs nonisolated https://byby.dev/swift-actor-isolation
[22] swift-evolution/proposals/0316-global-actors.md at main – GitHub https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md
[23] Swift release cycle – Blog https://blog.released.info/2022/12/01/swift-release-cycle.html
[24] 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
[25] Swift 6 Incomplete Migration Guide for Dummies – BrightDigit https://brightdigit.com/tutorials/swift-6-async-await-actors-fixes
[26] Migrating to Swift 6 | Documentation https://swift.org/migration
[27] GitHub – sabapathy7/swift-concurrency https://github.com/sabapathy7/swift-concurrency
[28] A Conversation With Swift 6 About Data Race Safety – Quality Coding https://qualitycoding.org/conversation-swift6-data-race-safety/
[29] [Prospective Vision] Improving the approachability of data-race safety https://forums.swift.org/t/prospective-vision-improving-the-approachability-of-data-race-safety/76183/44
[30] Breaking changes in Swift 6 – Page 3 – Discussion https://forums.swift.org/t/breaking-changes-in-swift-6/35928?page=3
[31] Enabling Strict Concurrency in Swift 6 https://swiftpublished.com/article/enabling-strict-concurrency-in-swift-6
[32] swiftlang/swift-evolution – GitHub https://github.com/swiftlang/swift-evolution
[33] How to Deprecate old API in Swift | Sarunw https://sarunw.com/posts/deprecate-old-api-in-swift/
[34] swift-migration-guide/Guide.docc/Swift6Mode.md at main · apple/swift-migration-guide https://github.com/apple/swift-migration-guide/blob/main/Guide.docc/Swift6Mode.md
[35] Swift Evolution Monthly: First Issue https://www.fline.dev/swift-evolution-monthly-first-issue/
[36] How do I move my project to Swift 6? | Ask WWDC https://askwwdc.com/q/2886
[37] How to plan a migration to Swift 6 – Donny Wals https://www.donnywals.com/how-to-plan-a-migration-to-swift-6/
[38] 바삭한 신입들의 동시성 이야기 – Swift편 – 데브시스터즈 기술 블로그 https://tech.devsisters.com/posts/crunchy-concurrency-swift/

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다