首先,没必要在Swift中做到这一点,有Obj-C代码和文档。
例:
CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString*)kUTTypeJSON];
attributeSet.title = title;
attributeSet.contentDescription = description;
attributeSet.keywords = @[keywords];
attributeSet.thumbnailData = thumbnailData;
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:identifier domainIdentifier:domainIdentifier attributeSet:attributeSet];
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler: ^(NSError * __nullable error) {
NSLog(@"Indexed");
}];
我想他们你想要的方式去了解这是使你加载完成后调用函数/呈现解析信息(即基本上随时随地你PFTableViewController的表视图更新)
你将不得不做一个for循环,并使其非常动态地获取每个单元格/行的信息。
就核心聚光灯搜索中显示的内容而言,您必须为每个项目设置关键字。请注意,关键字区分大小写,在我注意到之前花了我一段时间。这些关键字将与该单元格/行匹配。
至于打开的应用程序,也可以在你的appdelegate在您使用的NSUserActivity,通过它用户信息或不过想要去了解它,并从那里到信息使用的方法打开某个页面。
-(BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler
希望这有助于!让我知道如果我可以做任何其他事情来使这一点更清晰一点,因为我知道我不是最简洁的事情。快乐的编码!
回复@ user717452在这里评论为更好的造型
你提到SWIFT只让我表现出的外观目标C代码的Spotlight搜索等。
您可以循环遍历PFObjects,假设它是一个PFObjects数组,只需执行常规for循环和带有字典的可变数组即可。假设你的PFObject是这样的:parse.com/docs/ios/api/Classes/PFObject.html
NSMutableArray *mutArray = [[NSMutableArray alloc] init];
for(int i=0; i<pfobjectArray.count;i++ {
[mutArray addObject:@{@"title":[pfobjectArray[i] title], @"keywords":[pfobjectArray[i] keywords], @"thumbnail_data":[pfobjectArray[i] thumbnail], @"identifier":[pfobjectArray[i] identifier]}];
}
然后使用 “mutArray” 为spotlightSearch。
for(int i=0; i<mutArray.count;i++) {
CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString*)kUTTypeJSON];
attributeSet.title = mutArray[i][@"title"];
attributeSet.contentDescription = mutArray[i][@"description"];
attributeSet.keywords = [NSArray arrayWithArray:mutArray[i][@"keywords"]];
attributeSet.thumbnailData = mutArray[i][thumbnail_data];
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:mutArray[i][@"identifier"] domainIdentifier:@"com.iphone.app" attributeSet:attributeSet];
[arrayOfItems addObject:item];
}
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:[arrayOfItems mutableCopy] completionHandler: ^(NSError * __nullable error { NSLog(@"Spotlight Popular"); }];
我得到了如何创建它,更多的问题是关于如何循环访问PFObjects。 – user717452
@ user717452更新了我的答案 – Chris