Upgrade to Pro — share decks privately, control downloads, hide ads and more …

"What's new in Swift"の要約 / swift_5_9_summary

uhooi
June 22, 2023

"What's new in Swift"の要約 / swift_5_9_summary

uhooi

June 22, 2023
Tweet

More Decks by uhooi

Other Decks in Programming

Transcript

  1. 4& JGࣜͱTXJUDI͕ࣜ௥Ճ͞Εͨ // Swift 5.8 let isUhooi = { switch

    monster { case .uhooi: return true case .chibird: return false } }() // Swift 5.8 let foo = { if bar == 0 { return "Foo" } else { return "Bar" } }()
  2. 4& JGࣜͱTXJUDI͕ࣜ௥Ճ͞Εͨ // Swift 5.9 let isUhooi = switch monster

    { case .uhooi: true case .chibird: false } // Swift 5.9 let foo = if bar == 0 { "Foo" } else { "Bar" }
  3. 4& "UUBDIFE.BDSPT͕௥Ճ͞Εͨ // Swift 5.9 import Observation @Observable final class

    MonsterViewModel { var name = "" var description = "" init(name: String, description: String) { self.name = name self.description = description } }
  4. 4& 'SFFTUBOEJOH%FDMBSBUJPO.BDSPT͕௥Ճ͞Εͨ // Swift 5.9 import PowerAssert let a =

    -1 let b = 10 let c = 17 #assert(max(a, b) == c) | | | | | 10 -1 10 | 17 false
  5. 4& Մม௕ͷܕΛந৅ԽͰ͖Δ // Swift 5.8 static func buildBlock<C0, C1, C2,

    C3, C4, C5, C6, C7, C8, C9>( _ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8, _ c9: C9 ) -> TupleView<(C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where C0 : View, C1 : View, C2 : View, C3 : View, C4 : View, C5 : View, C6 : View, C7 : View, C8 : View, C9 : View { TupleView((c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)) }
  6. 4& Մม௕ͷܕΛந৅ԽͰ͖Δ // Swift 5.9 static func buildBlock<each Content>(_ content:

    repeat each Content) -> TupleView<(repeat each Content)> where repeat each Content : View { TupleView((repeat each content)) }
  7. 4& $PNCJOFʹґଘͤͣ؂ࢹͰ͖Δ // Swift 5.8 import Combine final class MonsterViewModel:

    ObservableObject { @Published var name: String @Published var description: String init(name: String, description: String) { self.name = name self.description = description } } struct MonsterView: View { @StateObject var viewModel: MonsterViewModel = .init(name: "Uhooi", description: "Foo") var body: some View { Text("Hello, \(viewModel.name)") } }
  8. 4& $PNCJOFʹґଘͤͣ؂ࢹͰ͖Δ // Swift 5.9 import Observation @Observable final class

    MonsterViewModel { var name = "" var description = "" init(name: String, description: String) { self.name = name self.description = description } } struct MonsterView: View { var viewModel: MonsterViewModel = .init(name: "Uhooi", description: "Foo") var body: some View { Text("Hello, \(viewModel.name)") } }
  9. 4& TUSVDUͱFOVNΛίϐʔෆՄೳʹ͢Δ // Swift 5.8 struct S { init() {

    print("S: init()") } // ❌: Deinitializers may only be declared within a class or actor deinit { print("S: deinit") } }
  10. 4& TUSVDUͱFOVNΛίϐʔෆՄೳʹ͢Δ // Swift 5.9 struct S: ~Copyable { init()

    { print("S: init()") } // ✅ deinit { print("S: deinit") } }