【问题标题】:Spotlight index issue after migration to Swift 3迁移到 Swift 3 后的 Spotlight 索引问题
【发布时间】: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 不会在我的应用程序中搜索任何内容。没有编译错误。

【问题讨论】:

    标签: ios swift3 spotlight


    【解决方案1】:

    我能够解决这个问题。 问题在循环中并从字典中分配。

    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
            }
    

    【讨论】:

      猜你喜欢
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多