【发布时间】:2017-01-26 09:33:43
【问题描述】:
最近我将我的 Xcode 项目转换为 Swift 3.0,现在我遇到了 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)
}
}
但是当我运行应用程序时,Spotlight 不会在我的应用程序中搜索任何内容。没有编译错误。
【问题讨论】: