I use NSUserActivity
to index a user activity for searching. I found a solution to delete a specific NSUserActivity
, assign a CSSearchableItemAttributeSet
with relatedUniqueIdentifier
to NSUserActivity
:
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeContact as String)
attributeSet.relatedUniqueIdentifier = objectId
let activity = NSUserActivity(activityType: Employee.domainIdentifier)
activity.title = name
activity.userInfo = userActivityUserInfo
activity.keywords = [email, department]
activity.contentAttributeSet = attributeSet
And delete it use
[[CSSearchableIndex defaultSearchableIndex]
deleteSearchableItemsWithIdentifiers: objectId completionHandler:^(NSError *deletionError) {
if (deletionError) {
NSLog(@"Could not delete items from the search index with error %@", deletionError);
}
}];
I don't know if it is a right solution or not. Do you have a better solution to delete a specific NSUserActivity
search index?