Showcase app data in Spotlight

RSS for tag

Discuss the WWDC21 session Showcase app data in Spotlight.

Posts under wwdc21-10098 tag

2 Posts

Post

Replies

Boosts

Views

Activity

On Continue User Activity with Swift UI
Hi All, I'm very new to iOS development and Swift UI is my first coding language. I'm trying to link the users search results in Spotlight with the detail view that is stored in Core Data. I can search for users data in spotlight but when I tap on it, it's only appearing in the main view of the app. Is there anyways that I can use .onContinueUserActivity at the launch of the app or is there any different code that I have to use? I've searched for many articles but I couldn't get a solution. It would be good if anyone can share some links or guide here. Thank you. .onContinueUserActivity(DetailView.productUserActivityType) { userActivity in             if let product = try? userActivity.typedPayload(Product.self) {                 selectedProduct = product.id.uuidString             }         } I get this code from Apple's State restoration app but I can't use this with Core Data.
1
0
1.9k
Aug ’24
Custom attribute for CSSearchableItemAttributeSet seems not working
In the document it says you can define your own custom attribute: The attributes you choose depend on your domain. You can use the properties that Core Spotlight provides in categories that CSSearchableItemAttributeSet defines (such as Media and Documents), or you can define your own. If you want to define a custom attribute, be as specific as possible in your definition and use the contentTypeTree property so that your custom attribute can inherit from a known type. I tried to index a custom attribute with the following code: class mySpotlightDelegate:NSCoreDataCoreSpotlightDelegate { static let myCustomAttr = CSCustomAttributeKey(keyName: "myCustomAttr")! override func attributeSet(for object: NSManagedObject) -> CSSearchableItemAttributeSet? { if let myObject = object as? MyObject { let attributeSet = CSSearchableItemAttributeSet(contentType: .bookmark) attributeSet.title = myObject.name attributeSet.setValue( NSString(string: myObject.myAttr), forCustomKey: mySpotlightDelegate.myCustomAttr ) return attributeSet } return nil } } But later I couldn't either search with the custom attribute nor get the value of that custom attribute in the CSSearchQuery foundItemsHandler. (The search returns nil and when searched with title it was fine, but when I tried to get the value of custom attribute of returned items with item.attributeSet.value(forCustomKey: mySpotlightDelegate.myCustomAttr), the value is always nil) I've read through all official document regarding this and also searched everywhere but can't find an example of this anywhere, execept 2 other developers complaining about this problem. Is this a bug, or I'm doing it wrong? What's the right way to do it?
0
0
1k
Feb ’22
On Continue User Activity with Swift UI
Hi All, I'm very new to iOS development and Swift UI is my first coding language. I'm trying to link the users search results in Spotlight with the detail view that is stored in Core Data. I can search for users data in spotlight but when I tap on it, it's only appearing in the main view of the app. Is there anyways that I can use .onContinueUserActivity at the launch of the app or is there any different code that I have to use? I've searched for many articles but I couldn't get a solution. It would be good if anyone can share some links or guide here. Thank you. .onContinueUserActivity(DetailView.productUserActivityType) { userActivity in             if let product = try? userActivity.typedPayload(Product.self) {                 selectedProduct = product.id.uuidString             }         } I get this code from Apple's State restoration app but I can't use this with Core Data.
Replies
1
Boosts
0
Views
1.9k
Activity
Aug ’24
Custom attribute for CSSearchableItemAttributeSet seems not working
In the document it says you can define your own custom attribute: The attributes you choose depend on your domain. You can use the properties that Core Spotlight provides in categories that CSSearchableItemAttributeSet defines (such as Media and Documents), or you can define your own. If you want to define a custom attribute, be as specific as possible in your definition and use the contentTypeTree property so that your custom attribute can inherit from a known type. I tried to index a custom attribute with the following code: class mySpotlightDelegate:NSCoreDataCoreSpotlightDelegate { static let myCustomAttr = CSCustomAttributeKey(keyName: "myCustomAttr")! override func attributeSet(for object: NSManagedObject) -> CSSearchableItemAttributeSet? { if let myObject = object as? MyObject { let attributeSet = CSSearchableItemAttributeSet(contentType: .bookmark) attributeSet.title = myObject.name attributeSet.setValue( NSString(string: myObject.myAttr), forCustomKey: mySpotlightDelegate.myCustomAttr ) return attributeSet } return nil } } But later I couldn't either search with the custom attribute nor get the value of that custom attribute in the CSSearchQuery foundItemsHandler. (The search returns nil and when searched with title it was fine, but when I tried to get the value of custom attribute of returned items with item.attributeSet.value(forCustomKey: mySpotlightDelegate.myCustomAttr), the value is always nil) I've read through all official document regarding this and also searched everywhere but can't find an example of this anywhere, execept 2 other developers complaining about this problem. Is this a bug, or I'm doing it wrong? What's the right way to do it?
Replies
0
Boosts
0
Views
1k
Activity
Feb ’22