0

Recently I converted my Xcode project to Swift 3.0 and now I have problem with Spotlight indexing. I'm using those final indexing of my values:

var searchableItems: [CSSearchableItem] = []
    let nameDays = ND.allnames()

    for (key, item) in nameDays as! [String:AnyObject] {
        let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String)
        let locItem = item["CZ"] as AnyObject
        if (locItem["long"] is String) {
            attributeSet.title = locItem["long"] as? String
        }
        else {
            attributeSet.title = locItem["basic"] as? String
        }
        let todayArr = key.characters.split{$0 == "-"}.map(String.init)
        let day = String(Int(todayArr[1])!) + "." + String(Int(todayArr[0])!) + "." as String
        attributeSet.contentDescription = day

        let searchableItem = CSSearchableItem(uniqueIdentifier: key, domainIdentifier: "namedays", attributeSet: attributeSet)
        searchableItems.append(searchableItem)
    }

CSSearchableIndex.default().indexSearchableItems(searchableItems) { (error) -> Void in
        if error == nil {
            print("Searchable items were indexed successfully")
        } else {
            print(error?.localizedDescription)
        }
}

But when I run the app, Spotlight don't search anything within my app. There are no compile errors.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
kecinzer
  • 3
  • 2

1 Answers1

0

I was able to fix this issue. Problem was in loop and assigning from dictionary.

let locItem = item.object(forKey: "CZ") as AnyObject!
        if (locItem?["long"] is String) {
            attributeSet.title = locItem?["long"] as? String
        }
        else {
            attributeSet.title = locItem?["basic"] as? String
        }
kecinzer
  • 3
  • 2