0

I've an iOS app that has spotlight search feature which allows user to search items from an app. It works fine on iOS app enter image description here

I am in the process of migrating the app as a catalyst app, somehow the spotlight search on mac catalyst app is not working

enter image description here

So far following things have been checked

  • Spotlight search logic is working as expected, there are no errors
  • Restarted Mac
  • Open catalyst app multiple times just to check if it is syncing with core spotlight and it is.
  • No previous issues registered on stack-overflow

Env: macOS 12.0.1

P.S: I am unsure if it is related to specific to my code as it is working fine on iPad and iPhone devices.

let attributeSet = CSSearchableItemAttributeSet(contentType: .content)
                    attributeSet.title = decodeItem.name
                    attributeSet.relatedUniqueIdentifier = decodeItem.id
                    attributeSet.url = URL.init(string: decodeItem.url)
                    
                    
                    let searchableItem = CSSearchableItem(uniqueIdentifier: decodeItem.id,
                                                          domainIdentifier: "com.xxx.xxxx",
                                                          attributeSet: attributeSet)
                    
searchableItems.append(searchableItem)

                      CSSearchableIndex.default().indexSearchableItems(searchableItems) { error in
                    if let error = error {
                        print("Issue indexing: \(error)")
                    } else {
                        print("Indexed.")
                    }
}
user4150758
  • 384
  • 4
  • 17

1 Answers1

-1

Found the issue: Assign value to attributeSet.relatedUniqueIdentifier only from initializer

user4150758
  • 384
  • 4
  • 17
  • Hi there, I'm struggling with the same or a similar problem - could you elaborate on your solution? `CSSearchableItemAttributeSet` can only be initialized with a `contentType` (or `itemContentType` String, thought that is deprecated). So `relatedUniqueIdentifier` has to be assigned after initializing `CSSearchableItemAttributeSet`, just like you do in your code above, right? How exactly did you get it to work? – julsh Mar 23 '22 at 01:35