iosswiftspotlightcorespotlight

how to remove thumbnailData in CSSearchableItemAttributeSet


My indexed data don't have a photo, so I don't want to show a photo, I only want the title and description: error

I have tried to set:

attributes.thumbnailData = nil

But it stil shows this blank image.

static func setupSearchableContentForSpotlight() {
    let realm = try! Realm(configuration:Constants.realmConfigration.wordsConfigration)
    var words: Results<Word>!
    words = realm.objects(Word.self)
    var searchableItems = [CSSearchableItem]()
    words?.forEach { word in
        let attributes = CSSearchableItemAttributeSet(itemContentType: kUTTypeData as String)
        attributes.title = word.defination
        attributes.contentDescription = word.meaning
        attributes.thumbnailData = nil
        let searchableVegetable = CSSearchableItem(uniqueIdentifier: nil, domainIdentifier: nil, attributeSet: attributes)
    }
    CSSearchableIndex.default().indexSearchableItems(searchableItems) { (error) -> Void in
        print("indxing completed")
        UserDefaults.standard.set(true, forKey: "spotLightIndexed")
        if let error = error  {
            print(error.localizedDescription)
        }
    }
}

I expect to for example the result to be with only:

exams

الماس

without this blank image. note: the app already has display icons.


Solution

  • The problem solved by restarting my iPhone.

    Extra tip: if you are dealing with CoreSpotlight, restaurant your iPhone after significant changes.