0
最近我将Xcode项目转换为Swift 3.0,现在我遇到了Spotlight索引问题。我用我的价值观的那些最终索引:迁移到Swift 3之后的Spotlight索引问题
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)
}
}
但是当我运行的应用程序,焦点不搜索我的应用程序内的任何东西。没有编译错误。