본문 바로가기
iOS/WWDC

[WWDC 2021] What‘s new in Swift

by HaningYa 2021. 6. 9.
728x90

https://developer.apple.com/videos/play/wwdc2021/10192/

 

What‘s new in Swift - WWDC 2021 - Videos - Apple Developer

Join us for an update on Swift. Discover the latest language advancements that make your code easier to read and write. Explore the...

developer.apple.com

Swift5.5 

  • swift concurrency
  • async await

packages: 원래 Swift packages Index -> Swift Package manager 지원하는 패키지 찾을 수 있음
근데 이번 업데이트로 xcode에서 바로 찾을 수 있음

Swift Package Collection -> 바로 Xcode에서 추가할 수 있음

 

import 에서 바로 패키지 다운받을 수 있음

https://swift.org/blog/package-collections/ 여기 정보가 있음

apple 오픈소스 packages

 

Swift Collections

- 스위프트 데이터 구조

Deque,

OrderedSet,

OrderedDictionary

Algorithms packages

- meet the swift algorithm 2021 에서 더 자세하게 다룸

Swift System

시스템콜 로우레벨 인터페이스

apple linux window에서 사용 가능

Swift Numerics

Float16 support to apple silicon Macs

Complex elementary functions

Swift ArgumentParser Package

Fish Shell completion scripts

joined short options

imporved error messages

Swift on Server

Static linking on Linux: 싱글 파일로 배포 가능해짐

Imporve JSON performance: 리눅스에서 성능 향상

Enhanced AWS Lambda runtime: 성능 향상

클로져 대신 async/await

Developer Documentation - Swift DocC

easy to write and share documentation

opensource 될꺼임

Type checker improve

이런 에러 줄어들 꺼임

Build imporvements

Faster builds when changing imported modules

Faster startup time before launching compiles

fewer recompliation after changing an extension body

recompile file 줄어들고 rebuild time 줄어들었다.

Memory Management

swift class 는 ARC를 사용한다.

대부분의 경우 메모리 관리에 대해서 신경쓸 필요가 없다.

Optimize Object lifetimes 을 통해 좀더 공격적인 메모리 관리가 가능하다.
ARC in Swift: Basics and beyond session 참고

Swift Ergonomic imporvements

Result bulder: 원래 SwiftUI를 위해서 만들어짐, 복잡한 객체 계층을 정의하기 위해 사용됨, 일반적인 사용을 위해 다시 정리되었음
- WWDC2021 Write a DSL in swift using result builders

codable synthesis 코더블 프로토콜 준수하려면 보일러 플레이트 코드가 많이 필요했다.
-> 이제는 컴파일러가 알아서 해줌 

Swift type checker: flexible static member look up

Property wrappers on parameters

Simple SwiftUI code sample

CGFloat 랑 Double이랑 이제 알아서 변환해준다ㅠㅠ

- WWDC 2021 What's new in swiftui

Asynchronous and concurrent programming

async 사용하기 전의 코드

순서가 약간 이상함
태스크를 만들고 task.resume()를 통해 일단 리턴해줌. 그리고 네트워킹이 끝나면 completion handler를 통해 끝남
모든 경우 Error를 completion handler와 함께 넘겨줘야함

async 사용 후 코드

코드 순서대로 이벤트 일어남
await에서 실행을 기다림

멈췄을때 쓰레드를 block 하지 않고 다른 리소스를 사용하지도 않음

문법적으로 async/await 키워드는 thows 와 try처럼 사용됨

- Meet async/await in Swift
- Swift concurrency: behind the scenes

Structed Concurrency

asyc/await 사용해서 만들어진 concurrency

이전의 렌더링 기능

동시성 적용된 렌더링 기능

async let 을 통해 병렬적으로 variable init 함

백그라운드 태스크는 이 함수 밖의 생명주기 밖으로 나갈 수 없음
함수 내에서 에러가 발생할 경우 런타임은 백그라운드 태스크를 기다릴 것음

에러를 던질 경우 백그라운드 태스크에 시그널 줘서 빨리 끝나도록 cancelation mechanism 등 추가 필요
- Explore structed concurrency in swift

멀티 쓰레드에서 발생하는 데이터 공유 inconsistency를 Swift Actors를 통해 해결할 수 있음

아래 코드는 멀티 쓰레드에서 여러개가 increment할 경우 오염될 수 있음

 class 를 actor로 변경하면 문제를 해결해줌

actor는 data curruption을 일으킬 수 있는 다른 쓰레드를 기다리게 만듬

actor 는 asyc/await 과 함께 사용해서 네트워크 결과 올때까지 기다리게 할 수 있으면서 다른 쓰레드가 이 increment 에도 접근 가능하게 하면서도 data 오염의 위험도 없게 해준다. 

actor는 reference type이지만 몇가지 룰을 따르면서 병렬 실행에 안전할 수 있게 만들어졌다.

- WWDC2021 protect mutable state with swift actors

looking ahead Swift6

swift5.5 #async/await  #stuctured concurrency #actor

Swift6 #safe Concurrency

 

 

Related Videos

WWDC 2021

728x90

'iOS > WWDC' 카테고리의 다른 글

[WWDC 2021] What's new in SwiftUI  (0) 2021.06.09
WWDC 2021 Watch list  (2) 2021.06.09
Introducing PencilKit  (0) 2020.09.29

댓글