Post

Replies

Boosts

Views

Activity

SwiftUI TextField inside Toolbar on MacOS not trigger onChange of focusedState
struct ContentView: View { @State private var editTitle = "title" @FocusState private var isFocused: Bool var body: some View { NavigationSplitView { Text("sidebar") } detail: { Text("detail") .navigationTitle("") .toolbar { ToolbarItem(placement: .principal) { TextField("", text: $editTitle) .focused($isFocused) .onChange(of: isFocused) { oldValue, newValue in print("onChange") } } } } } } on iOS, onChange is triggerred when TextField is inside toolbar or not on MacOS, onChange is not triggerred when TextField is inside toolbar, but when not in toolbar, it works fine
0
0
155
Oct ’24
SwiftUI Picker not trigger `onChange` first time when inside Menu in MacOS
code import SwiftUI @main struct swiftuiTestApp: App { @State private var value = "a"; var body: some Scene { WindowGroup { Menu("menu") { Picker("", 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) } } } } } on MacOS, onChange is not triggered when an option is selected for the first time, but subsequent option selections are triggered。 on MacOS, when Picker is not inside Menu, it works fine on iOS, both works fine with inside or not inside menu
6
0
454
Sep ’24
Swiftdata using an existing CloudKit container, how to listen to the NSPersistentCloudKitContainer's NSPersistentStoreRemoteChange event
My app uses SwiftData and CloudKit to store and synchronize data. This works nice. in some scenarios, I need to listen to NSPersistentStoreRemoteChange event to deduplicate data. In SwiftData, how do I get the persistentStoreCoordinator of the corresponding SwiftData ModelContainer? Or are there other APIs to achieve the same purpose? There is no relevant content in the developer documentation. In addition, in wwdc 24, there is a new API to track history (https://developer.apple.com/cn/videos/play/wwdc2024/10075/). But there is no mention of how to listen to remote data change events either.
1
0
464
Aug ’24
swiftUI apps with SwiftData and CloudKit crashes on iOS but works on MacOS
sample code let modelConfiguration = ModelConfiguration() // 1. create mom guard let mom = NSManagedObjectModel.makeManagedObjectModel(for: [Attachment.self]) else { fatalError("====> makeManagedObjectModel error") } // 2. create description with config url and setting let description = NSPersistentStoreDescription(url: modelConfiguration.url); description.shouldAddStoreAsynchronously = false; container = NSPersistentCloudKitContainer(name: "swiftDataCloudTest", managedObjectModel: mom); container.persistentStoreDescriptions = [description] // 3. get modelContainer let modelContainer = try! ModelContainer(for: Attachment.self, configurations: self.modelConfiguration) this code works fine on MacOS(14.4.1) and previous iOS 17.x.(iOS 17.2 is OK) but on iOS 17.5, the app crashes with message A Core Data error occurred." UserInfo={NSLocalizedFailureReason=Unable to find a configuration named 'default' in the specified managed object model how can I fix these?
5
0
803
Jun ’24