Shrikar
Shrikar

Reputation: 870

CoreSpotlight indexing not working

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.

Upvotes: 3

Views: 1692

Answers (1)

Bannings
Bannings

Reputation: 10479

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.

Upvotes: 6

Related Questions