Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Picker not trigger `onChange` first time when inside Menu in MacOS
if I move onChange to Menu, the problem disappeared Menu("menu") { Picker("value \(value)", selection: $value) { Text("A").tag("a") Text("B").tag("b") Text("C").tag("c") } .pickerStyle(.inline) } .onChange(of: value) { oldValue, newValue in print("onChange", newValue) } but my goal is to encapsulate Picker into a controlled component similar to React, so I have to put state inside menu import SwiftUI struct TBSelect: View { let title: String; let value: String; let options: Array<TBSelectOption>; let tip: String; let onChange: (_ value: String) -> Void; @State private var innerValue: String; struct TBSelectOption { let title: String; let value: String; let systemImage: String?; } init(title: String, value: String, options: Array<TBSelectOption>, tip: String = "", onChange: @escaping (_ value: String) -> Void) { _innerValue = State(initialValue: value); self.title = title self.value = value self.options = options self.tip = tip self.onChange = onChange; } var body: some View { Picker(title, selection: $innerValue) { ForEach(options, id: \.value) { option in if let systemImage = option.systemImage { Label(option.title, systemImage: systemImage) .tag(option.value) } else { Text(option.title) .tag(option.value) } } } .help(tip) .onChange(of: innerValue) { oldValue, newValue in onChange(newValue) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’24
Reply to swiftUI apps with SwiftData and CloudKit crashes on iOS but works on MacOS
@FPST I tried with catch do { self.modelContainer = try ModelContainer(for: Document.self, CheckPoint.self, configurations: self.modelConfiguration) } catch let error { print(error); fatalError() } I can't find any clues with the error message CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate managedObjectContextSaved:](3113): <NSCloudKitMirroringDelegate: 0x600002aec2d0>: Observed context save: <NSPersistentStoreCoordinator: 0x600003beab80> - <NSManagedObjectContext: 0x600002eea150> CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate remoteStoreDidChange:](3156): <NSCloudKitMirroringDelegate: 0x600002aec2d0>: Observed remote store notification: <NSPersistentStoreCoordinator: 0x600003beab80> - BBB83AF9-4C01-4B3C-83E2-995E86857622 - (null) - file:///Users/xx/Library/Containers/com.test.swiftDataCloudTest/Data/Library/Application%20Support/default.store CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate remoteStoreDidChange:]_block_invoke(3206): <NSCloudKitMirroringDelegate: 0x600002aec2d0> - Ignoring remote change notification because it didn't change any entities tracked by persistent history: <NSSQLCore: 0x11f60e6d0> (URL: file:///Users/xx/Library/Containers/com.test.swiftDataCloudTest/Data/Library/Application%20Support/default.store) SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer)
Jun ’24
Reply to swiftUI apps with SwiftData and CloudKit crashes on iOS but works on MacOS
on MacOS 14.5, the app on Mac also crash with the same error Unresolved error loading container Error Domain=NSCocoaErrorDomain Code=134060 "A Core Data error occurred." UserInfo={NSLocalizedFailureReason=Unable to find a configuration named 'default' in the specified managed object model.} I think there is something todo with MacOS 14.5 and iOS 17.5.....
Jun ’24