Reputation: 11
I want to search a list by typing multi words from the detailed list. e.g, in a claim request list there are different type of lables such as amount, requestor name, request name and nos also. So i want to search anything from this label so that i can able to find the exact request.
Upvotes: 1
Views: 504
Reputation: 1242
May be this answer was helpful to you..
let addresspredicate = NSPredicate(format: "address_name contains[c] %@",searchText)
let accnopredicate = NSPredicate(format: "acc_no contains[c] %@",searchText)
let propertytype = NSPredicate(format: "property_type contains[c] %@",searchText)
let subpropertytypoe = NSPredicate(format: "subproperty_type contains[c] %@",searchText)
let predicateCompound = NSCompoundPredicate.init(type: .or, subpredicates: [addresspredicate,accnopredicate,propertytype,subpropertytypoe])
filteredProperty = (propertyArray as Array).filter { predicateCompound.evaluate(with: $0) };
print("filteredProperty = ,\(filteredProperty)")
Upvotes: 0
Reputation: 376
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)
Upvotes: 1