Component - Predicates and sorting
This UI component shows a list of items filtered by a condition (predicate) and sorted by a chosen property. Users see only the items that match the filter, arranged in order.
This UI component shows a list of items filtered by a condition (predicate) and sorted by a chosen property. Users see only the items that match the filter, arranged in order.
UITableViewController
└── UITableView
└── UITableViewCell (multiple)NSPredicate do in Swift when working with arrays?let names = ["Anna", "John", "Bob", "Alice"]
let predicate = NSPredicate(format: "SELF BEGINSWITH[c] 'A'")
let filtered = (names as NSArray).filtered(using: predicate) as! [String]
let sorted = filtered.sorted(by: { $0 > $1 })
print(sorted)let numbers = [5, 3, 8, 1]
let predicate = NSPredicate(format: "SELF > 4")
let filtered = numbers.filter { predicate.evaluate(with: $0) }
let sorted = filtered.sorted(by: { $0 < $1 })
print(sorted)let people = [ ["name": "John", "age": 30], ["name": "Alice", "age": 25], ["name": "Bob", "age": 30], ["name": "Carol", "age": 25] ]How do you filter for people aged 25 and sort them by name ascending using NSPredicate and Swift sorting?
Pass the test and this pattern moves unknown