Unknown Error when adding an CSSearchableItem to Core Spotlight (MacOS)
With macOS 10.13, SIP and the App Sandbox seem to have become a little more strict.
After a lot of digging to get this work, here's what I did, and should work for others reading this too:
- In Xcode, toggle the "App Sandbox" capability for your target in which your
CoreSpotlight
code runs. If this is in a framework, it needs to be the hosting application's target. This shouldn't be necessary for new projects (for details, see this bug report). - Enable development signing for the application/binary which will run the CoreSpotlight code. In my case, it was the test host.
Update Spotlight Search Index when working with Core Data?
You want the indexing to be in sync with the deletion of your items. Hence look for these three methods implemented by CSSearchableIndex class to delete items when they are no longer required.
- deleteAllSearchableItemsWithCompletionHandler(_:)
- deleteSearchableItemsWithDomainIdentifiers(_:completionHandler:)
- deleteSearchableItemsWithIdentifiers(_:completionHandler:)
Like this example,
CSSearchableIndex.defaultSearchableIndex().deleteSearchableItemsWithDomainIdentifiers(["tv-shows"]) { (error) -> Void in if error != nil { print(error?.localizedDescription) } else { // Items were deleted successfully }}
Trying to use CoreSpotlight on OSX
The CoreSpotlight documentation suggests that API was added on macOS in High Sierra (10.13).
SDKs
iOS 9.0+
macOS 10.13+
I can confirm it works for me on macOS 10.13.
Since you are running 10.12, the API does not exist.
Related Topics
Swift Notification Fire from Datepicker
Create Generic Delegate for Class
Reflection with Swift - Get Functions Name of a Class
Swift Threading with Dispatchgroup
Synchronized Realm - Airplane Mode
Parsing Fetched JSON to Dictionary in Swift 3
Swiftui Inputaccesoryview Implementation
Combining Watchconnectivity and Complications
iOS Charts Library - How to Handle X-Axis Duplicate Values
Swift Class Doesn't Like Self.View.Addsubview()
How to Call Presentviewcontroller from Inside Class
iOS 11 PDFkit Not Updating Annotation Position
Generate Avaudiopcmbuffer with Avaudiorecorder
Scenekit Physics Add Velocity in Local Space
Type '()' Cannot Conform to 'View'
Appending Text to Nstextview in Swift 3