gpt4 book ai didi

ios - 使用 NSPredicate 在一次搜索 iOS swift 中搜索多个单词

转载 作者:行者123 更新时间:2023-11-29 11:47:13 33 4
gpt4 key购买 nike

我想通过从详细列表中输入多个单词来搜索列表。例如,在 claim 请求列表中,有不同类型的标签,例如金额、请求者名称、请求名称和编号。所以我想搜索此标签中的任何内容,以便能够找到确切的请求。

In this image i have made a sample list having type, requestor, reg no and amount. I want to search the list by typing multi words using these params.

最佳答案

var predicateList = [NSPredicate]()

let words = filterText.componentsSeparatedByString(" ")

for word in words{

if count(word)==0{
continue
}

let RequestTypeArray = NSPredicate(format: "RequestType contains[c] %@", word)
let RequestEmployeeArray = NSPredicate(format: "RequestorEmployee contains[c] %@", word)
let RegesterNumberArray = NSPredicate(format: "ReqNo contains[c] %@", word)
let AmountOrDaysArray = NSPredicate(format: "AmountOrDays contains[c] %@", word)

let orCompoundPredicate = NSCompoundPredicate(type: NSCompoundPredicateType.OrPredicateType, subpredicates: [firstNamePredicate, lastNamePredicate,departmentPredicate,jobTitlePredicate])

predicateList.append(orCompoundPredicate)
}

request.predicate = NSCompoundPredicate(type: NSCompoundPredicateType.AndPredicateType, subpredicates: predicateList)

关于ios - 使用 NSPredicate 在一次搜索 iOS swift 中搜索多个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43060662/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com