Post

Replies

Boosts

Views

Activity

How to use core spotlight ?
Watched videos, blog post and downloaded their projects and there the core spot lights works accordingly. I copied code to an empty project and did the same as what they did but still is not working os: macOS and iOS on coredataobject I settled up a attribute to index for spotlight and in object it self I putted the attribute name in display name for spotlight. static let shared = PersistenceController() var spotlightDelegate: NSCoreDataCoreSpotlightDelegate? @MainActor static let preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext = result.container.viewContext for _ in 0..<10 { let newItem = Item(context: viewContext) newItem.timestamp = Date() } do { try viewContext.save() } catch { let nsError = error as NSError fatalError("Unresolved error \(nsError), \(nsError.userInfo)") } return result }() let container: NSPersistentContainer init(inMemory: Bool = false) { container = NSPersistentContainer(name: "SpotLightSearchTest") if inMemory { container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null") } container.loadPersistentStores(completionHandler: { [weak self] (storeDescription, error) in if let error = error as NSError? { fatalError("Unresolved error \(error), \(error.userInfo)") } if let description = self?.container.persistentStoreDescriptions.first { description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) description.type = NSSQLiteStoreType if let coordinator = self?.container.persistentStoreCoordinator { self?.spotlightDelegate = NSCoreDataCoreSpotlightDelegate( forStoreWith: description, coordinator: coordinator ) self?.spotlightDelegate?.startSpotlightIndexing() } } }) container.viewContext.automaticallyMergesChangesFromParent = true } } in my @main view struct SpotLightSearchTestApp: App { let persistenceController = PersistenceController.shared var body: some Scene { WindowGroup { ContentView() .environment(\.managedObjectContext, persistenceController.container.viewContext) .onContinueUserActivity(CSSearchableItemActionType) {_ in print("") } } } } onContinueUserActivity(CSSearchableItemActionType) {_ in print("") } never gets triggered. Sow What am I missing that they dont explain in the blog post or videos ?
3
0
176
Mar ’25
custom share workflow
I am working on a software where we want to add the feature to share the whole database with the other user. Database is iCloud combined with coredata. The other user(s) should be able to edit /delete and even create new objects in the share. I did this with this code witch directly from sample code let participants = try await ckConainer.fetchParticipants(matching: [lookupInfo], into: selectedStore) for participant in participants { participant.permission = .readWrite participant.role = .privateUser share.addParticipant(participant) } try await ckConainer.persistUpdatedShare(share, in: selectedStore) the other user gets invited and I can see this in iCloud database that the other user is invited with status invited. but the other user never gets a mail or something to accept and join the share. How does the other needs to accept the invitation ?
2
0
250
Mar ’25
pop over crash swiftUI on macOS
I have a question regarding popover. I am currently developing a macOS application were we create logs in core data when an attribute gets altered by the user. I want to display the logs in a table inside a popover. However when I start the app it opens the popover perfect for the first time but when the popover closes or want to reopen again it crashes with error: code=1, address=0x5a1a31562420. We don't refetch the logs when reopening the popover, the log amount stays the same. After investigating I came to the conclusion that it's due to an attribute that keeps crashing, but there are 2 other attributes that are exactly the same. model applicationLog: parent entity / abstract entity auditDateTime: Date optional field: String optional newValue: string optional -> attribute that crashes oldValue: string optional @Environment(\.managedObjectContext) private var viewContext @Binding var logs: [CustomerLog] var body: some View { Table(logs) { TableColumn("Date") { log in Text((auditDateTime(for: log))) } TableColumn("User") { log in Text(log.userName ?? "") } TableColumn("Old Value", value: \.oldValue) TableColumn("New Value", value: \.newValue) } solutions I tried: giving the context to the popover making logs bindable putting it in a lazyHStack inside a List
0
0
258
Dec ’23