Avatar
わいわいでも言った気がするけど、 @StateObject@ObservedObject なくなると Binding が簡単に取れなくなって困らないのかなぁ。 @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 ... } } }
2:04 AM
あと↓がっかりなんだけど、これミスなく手で書くの辛そう・・・。 @Observable マクロががんばってくれたりはしない? extension MyObject { var someComputedProperty: Int { somePrivateProperty + someOtherProperty } nonisolated static func dependencies( of keyPath: PartialKeyPath<Self> ) -> TrackedProperties<Self> { switch keyPath { case \.someComputedProperty: return [\.somePrivateProperty, \.someOtherProperty] default: return [keyPath] } } }
2:04 AM
さすがに無理か。