Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Archive
- FLUTTER
- error
- MacOS
- Xcode
- IOS
- JPA
- 한글
- 이미지
- appstore
- Session
- view
- github
- geofencing
- Firebase
- 웹뷰
- iOS16
- mac
- darkmode
- Apple
- rxswift
- Code
- Git
- UIButton
- 개발자
- window
- Swift
- Notification
- SwiftUI
- Realm
Archives
- Today
- Total
EEYatHo 앱 깎는 이야기
Swift ) Swift 5.7 변경사항 - EEYatHo iOS 본문
반응형
if let 약식 구문 등장
let foo: String? = "hello world"
// if let foo = foo {
if let foo {
print(foo)
}
any 확장
- any 키워드를 사용한 모듈을 만들 때,
type erase 로 type relationship 이 제거되어 associatedType 을 디스패치하지 못하던 상황을 개선
=> any 타입을 unboxing 하여 some 타입으로 컨버팅 할 수 있는 기능을 컴파일러에 추가
func feed(_ animal: some Animal) {
let food = type(of: animal).Feed.make() // associatedType 접근
animal.eat(food)
}
func feedAll(_ animals: [any Animal]) {
for animal in animals {
feed(animal) // some 타입으로 컨버팅
}
}
protocol Animal {
associatedtype Feed: AnimalFood
func eat(_ food: Food)
}
protocol AnimalFood {
static func make() -> Food
}
protocol Food {}
some 확장
- 프로퍼티 및 리턴 타입 뿐만 아니라, 파라미터 타입에도 some 키워드 사용 가능
func someFunc(_ v1: some Codable, _ v2: some Hashable) -> Int {...}
etc
https://github.com/apple/swift/blob/main/CHANGELOG.md#swift-57
- actor 변경사항
- 정규식 변경사항
- 시간을 나타내는 새로운 유형
- 클로저의 타입유추 범위 향상
- 제네릭 파라미터에 기본값 넣기 가능
- 최상위 스크립트에서의 await 허용 ( MainActor 에서 실행 )
Reference
Swift 5.7 Released!
Swift 5.7 is now officially released! Swift 5.7 includes major additions to the language and standard library, enhancements to the compiler for a better developer experience, improvements to tools in the Swift ecosystem including SourceKit-LSP and the Swif
www.swift.org
GitHub - apple/swift: The Swift Programming Language
The Swift Programming Language. Contribute to apple/swift development by creating an account on GitHub.
github.com
[Swift] some, any 키워드
WWDC 2022 > Embrace Swift Generics 에 나오는 내용입니다. Feed (사료, 먹이) 를 associatedtype으로 가지는 Animal 프로토콜을 예제로 사용합니다. [1] AS IS Farm에 feed라는 메소드를 만들고 싶을 때, 아래 두가지
eunjin3786.tistory.com
'iOS, Swift > Swift Theory' 카테고리의 다른 글
RxSwift ) 스케쥴러, Subscribe(on:), observe(on:) - EEYatHo iOS (0) | 2023.02.13 |
---|---|
Swift ) frame, bounds - EEYatHo iOS (0) | 2023.02.13 |
Swift ) async/await - EEYatHo iOS (0) | 2023.01.16 |
Swift ) Concurrency, Thread, GCD - EEYatHo iOS (0) | 2023.01.12 |
Swift ) Class vs Struct 성능 비교 - EEYatHo iOS (0) | 2023.01.06 |
Comments