与搜索有关联的领域过滤器对象

时间:2018-07-04 07:32:48

标签: swift realm nspredicate

我有一个搜索字段,用户可以在其中查询会话的属性以及该会话的发言人。扬声器通过扬声器的主键链接。一个会话可以有一个以上的发言人。

我的代码如下:

单词是搜索字段中的单词。

for word in words{

                if word.count==0{
                    continue
                }

                let titleENPredicate = NSPredicate(format: "titleEN contains[c] %@", word)
                let locationENPredicate = NSPredicate(format: "locationEN contains[c] %@", word)
                let descriptionENPredicate = NSPredicate(format: "sessionDescriptionEN contains[c] %@", word)


                let speakerIDs = filterSpeakerNames(filterText, inputList: self.realm.objects(Participant.self)).sorted()
                let speakerIDPredicate = NSPredicate(format: "speakerIds IN %@", speakerIDs)

                let orCompoundPredicate = NSCompoundPredicate(type: NSCompoundPredicate.LogicalType.or,
                                                              subpredicates: [titleENPredicate, locationENPredicate, descriptionENPredicate, speakerIDPredicate])
                predicateList.append(orCompoundPredicate)
            }

            let compoundPredicate = NSCompoundPredicate(type: NSCompoundPredicate.LogicalType.and, subpredicates: predicateList)
            let filteredSessions = inputList.filter(compoundPredicate)

如果我输入了SpeakerIDPredicate,我会得到:

  

speakerIds IN {“ 00dabebe-4275-40e1-9889-500e73d544ef”,   “ 0c44fb9c-984d-47bc-9fd0-c1ba6b5c4150”,   “ 987bc697-ec2c-42e6-abd0-85de1bb4e70a”,   “ e5160cf6-4b32-4c20-931e-38eb777ec744”,   “ e54c6f0e-2684-4400-a28f-3e3e7b5e4035”}

但是我崩溃了

  

由于未捕获的异常“无效谓词”而终止应用程序,原因:   '包含数组属性的键路径必须使用汇总   操作”

0 个答案:

没有答案