CoreSpotlight indexing not working

1.6k Views Asked by At

I am using the CoreSpotLight api to index some content. For some reason I am not able to find the data when I search in the SpotLight.

let atset:CSSearchableItemAttributeSet = CSSearchableItemAttributeSet()  
atset.title = "Simple title"  
atset.contentDescription = "Simple twitter search"  
let item = CSSearchableItem(uniqueIdentifier: "id1", domainIdentifier: "com.shrikar.twitter.search", attributeSet: atset)  
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([item]) { (error) -> Void in  
 print("Indexed")  
}  

When I run the app I see that the data is indexed and the error is nil. Also I have added the CoreSpotLight and MobileCoreServices to the build phase.

1

There are 1 best solutions below

5
On BEST ANSWER

Try use itemContentType initializer like so :

let atset:CSSearchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
atset.title = "Simple title"
atset.contentDescription = "Simple twitter search"
let item = CSSearchableItem(uniqueIdentifier: "id1", domainIdentifier: "com.shrikar.twitter.search", attributeSet: atset)
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([item]) { (error) -> Void in
    print("Indexed")  
}

The kUTTypeImage is declared in MobileCoreServices.