I read on some tutorial, and found that NSUserActivity
for index info when user make an activity, Core Spotlight
for index a set of content data in app.
Use NSUserActivity
var activity = NSUserActivity(activityType: "com.example.demo.searchapi")
activity.title = contactEntity.name
activity.userInfo = ["id": contactEntity.uid]
activity.eligibleForSearch = true
activity.keywords = NSSet(array: [contactEntity.name,contactEntity.phoneNumber, contactEntity.email]) as! Set
activity.becomeCurrent()
Use Core Spotlight
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeContact as String)
attributeSet.title = contactEntity.name
attributeSet.relatedUniqueIdentifier = contactEntity.uid
let searchableItem = CSSearchableItem(uniqueIdentifier: contactEntity.uid, domainIdentifier: "com.example.demo.searchapi", attributeSet: attributeSet)
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems(searchableItems) { error in
if let error = error {
print("Error indexing: \(error)")
} else {
print("Indexed.")
}
But I don't think there is difference between two solution result. If user make an activity, I can use Core Spotlight
, instead of NSUserActivity
. It give me same result.
So, why Apple have to provide two difference solutions which have same result?
NSUserActivity
in iOS 9 hascontentAttributeSet
, which is of typeCSSearchableItemAttributeSet
– onmyway133