---
# System prepended metadata

title: WWDCを先取りかも？気になる最近のswift大規模変更

---

# WWDCを先取りかも？気になる最近のswift大規模変更

## if switch式

https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md

ifとswitchが特定条件下で式に

## Observation

https://github.com/apple/swift-evolution/blob/main/proposals/0395-observability.md

次のSwiftUIは結構変わるかも？

```swift=
final class Model: ObservableObject {
    @Published var order: Order?
    @Published var account: Account?
    
    var hasAccount: Bool {
        return userCredential != nil && account != nil
    }
    
    @Published var favoriteSmoothieIDs = Set<Smoothie.ID>()
    @Published var selectedSmoothieID: Smoothie.ID?
    
    @Published var searchString = ""
    
    @Published var isApplePayEnabled = true
    @Published var allRecipesUnlocked = false
    @Published var unlockAllRecipesProduct: Product?
}

struct SmoothieList: View {
    var smoothies: [Smoothie]
    @ObservedObject var model: Model
    
    var listedSmoothies: [Smoothie] {
        smoothies
            .filter { $0.matches(model.searchString) }
            .sorted(by: { $0.title.localizedCompare($1.title) == .orderedAscending })
    }
    
    var body: some View {
        List(listedSmoothies) { smoothie in
            ...
        }
    }
} 
```

Observation使用バージョン

```swift=
@Observable final class Model {
    var order: Order?
    var account: Account?
    
    var hasAccount: Bool {
        return userCredential != nil && account != nil
    }
    
    var favoriteSmoothieIDs: Set<Smoothie.ID> = []
    var selectedSmoothieID: Smoothie.ID?
    
    var searchString: String = ""
    
    var isApplePayEnabled: Bool = true
    var allRecipesUnlocked: Bool = false
    var unlockAllRecipesProduct: Product?
}

struct SmoothieList: View {
    var smoothies: [Smoothie]
    var model: Model
    
    var listedSmoothies: [Smoothie] {
        smoothies
            .filter { $0.matches(model.searchString) }
            .sorted(by: { $0.title.localizedCompare($1.title) == .orderedAscending })
    }
    
    var body: some View {
        List(listedSmoothies) { smoothie in
            ...
        }
    }
} 
```

## マクロ

ついにswiftに強力なマクロが

岸川さんがPower Assert作っている

https://forums.swift.org/t/a-possible-vision-for-macros-in-swift/60900/87