Post

Replies

Boosts

Views

Activity

Reply to Drag & Drop issues in SwiftUI in a Playground App
To test my hypothesis about the environment being the cause, I replaced my two custom UTIs with system UTIs (public.item and public.folder). The missing provider issues went away, my code was working but the system was not making the custom UTIs available to the DropDelegate. However, the issue I raised with the filter not working in onDrop(of:delegate:) still seems broken.
Jan ’22
Reply to Push to CloudKit from Share Extension
I no longer find this solution works reliably.Sending a DarwinNotification from the App Extension to the App may be making it more reliable.If it really needs this Notification, it would make me think of two issues :CloudKit synchronisation is not functioning properly when data is saved to CoreData in a shared App Group by an App Extension.For correct synchronisation to occur after a save from an App Extension, the containing App would have to be running.The real problem is reliability.Sometimes, the save does propogate to other devices in both cases (parent app running or not), sometimes it does not.Sometimes the propogation is partial (missing relationships).Should I expect CoreData + CloudKIT as it stands to be production-ready or am I doing something wrong?
May ’20
Reply to Behaviour after presentation in Sheet vs NavigationLink
I have resolved this but still do not know why the two ways of presenting made such a big difference.Instead of having a @State var on the View (bound to the SearchField, sent to the SearchPublisher), I performed the binding inside the SearchPublisher by adding a new @Published var :@Published private(set) var hits = [ThingViewModel]() @Published var term: String = UserDefaults.standard.string(forKey: .key) ?? "" { didSet { guard let search = term.trimmed(), !search.isEmpty else { self.hits = [] UserDefaults.standard.removeObject(forKey: .key) return } self.perform(self.predicate(search)) UserDefaults.standard.set(search, forKey: .key) } }Then bind the SearchField directly to it :SearchBar(text: self.$thingSearch.term, placeholder: "Search for Things")However, this does not answer the original question.
Apr ’20
Reply to @FetchRequest not refreshing
I have got it working now but for what feel like all of the wrong reasons.I moved the notification handler up a level, so that the view that contains all of the @FetchRequest is force refreshed by being re-constructed.The solution feels dirty, I still beleive that the @FetchRequest should be able to trigger a data reload itself when the data changes.The top level ContentView is now having to be very heavy handed IMHO. by: struct ContentView: View { private var didUpdate = NotificationCenter.default.publisher(for: .coreDataRemoteChange) @State private var renderID = UUID() var body: some View { NavigationView { MasterListView() .navigationBarTitle(Text("Things")) .navigationBarItems( trailing: EditButton() ) Text("No Content").noContentStyle() Print("ContentView \(renderID)") } .id(self.renderID) .onReceive(self.didUpdate) { _ in print("ContentView received .coreDataRemoteChange") self.renderID = UUID() } .navigationViewStyle(DoubleColumnNavigationViewStyle()) .accentColor(.accent) } }... attaching a UUID to the NavigationView.Because the notification is reliable and the data was actually being updated, techniques likeNSManagedObjectContext.mergeChanges(fromRemoteContextSave: [NSInsertedObjectsKey: addedThings], into: [taskContext])are not actually required.I would be surprised if this was the way we are intended to use @FetchRequest
Apr ’20