Hello,
I'm trying to get the keywords I added to an item. I run the following code and my items are indexed as expected.
A few questions to you guys:
1. How do I get the attributeSet.keywords
2. Why is it converted to userActivity: NSUserActivity in the continueUserActivity
Currently when I do:
if let keywords = userActivity.contentAttributeSet?.keywords {
chartDetailTabBarController.companyName = keywords[1]
chartDetailTabBarController.searchDescription = keywords[2]
}
keywords is nil
Now I assumed since its converted to an NSUserActivity, that it might have moved to
let keywords = userActivity.keywords
but this returns keywords = []
@available(iOS 9.0, *)
func addToSpotlight(title: String, companyName: String, contentDescription: String, image: NSData?, uniqueIdentifier: String, domainIdentifier: String) {
let attributeSet:CSSearchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
attributeSet.title = title
attributeSet.contentDescription = contentDescription
attributeSet.thumbnailData = image
attributeSet.keywords = [title, companyName, contentDescription, "Stocks", "Markets"]
let searchableItem = CSSearchableItem(uniqueIdentifier: uniqueIdentifier, domainIdentifier: domainIdentifier, attributeSet: attributeSet)
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([searchableItem]) { (error) -> Void in
if let error = error {
print("Deindexing error: \(error.localizedDescription)")
} else {
print("Search item successfully indexed!")
}
}
}
@available(iOS 9.0, *)
func createNSUserActivity(title: String, companyName: String, contentDescription: String, image: NSData?, uniqueIdentifier: String, domainIdentifier: String) {
let attributeSet:CSSearchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
attributeSet.contentDescription = contentDescription
/
attributeSet.relatedUniqueIdentifier = title
let activity: NSUserActivity = NSUserActivity(activityType: domainIdentifier)
activity.title = title
activity.keywords = NSSet(array: [title, companyName, contentDescription, "Stocks", "Markets"]) as! Set<String>
activity.userInfo = ["symbol": title, "companyName": companyName, "searchDescription": contentDescription]
activity.contentAttributeSet = attributeSet
activity.eligibleForSearch = true
activity.eligibleForPublicIndexing = true
activity.requiredUserInfoKeys = NSSet(array: ["title", "userInfo", "contentAttributeSet", "eligibleForSearch", "eligibleForPublicIndexing"]) as! Set<String>
userActivity = activity
activity.becomeCurrent()
print("NSUserActivity created")
}