Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let keyword: String? = ""
- let type: String? = ""
- let use: String? = ""
- let max: Int? = 0
- let min: Int? = 4
- let orgsearchDataModel: [Datum] = []
- extension String {
- func contains(_ string: String, caseInsenstive: Bool = true) -> Bool {
- return range(of: string, options: caseInsenstive ? .caseInsensitive : []) != nil
- }
- }
- extension Datum {
- func matchAddress(_ string: String?) -> Bool {
- guard let string = string else { return true }
- guard let address = listingAddress else { return true }
- return address.contains(string)
- }
- func matchType(_ string: String?) -> Bool {
- guard let string = string else { return true }
- return listingType.contains(string)
- }
- func matchUse(_ string: String?) -> Bool {
- guard let string = string else { return true }
- return listingUse.contains(string)
- }
- func isIncludedBetween(min: Int?, max: Int?) -> Bool {
- guard let listingPrice = listingPrice, let price = Int(listingPrice) else { return false }
- return price >= (min ?? Int.min) && price <= (max ?? Int.max)
- }
- }
- let filtered = orgsearchDataModel.filter {
- return $0.matchAddress(keyword) && $0.matchUse(use) && $0.matchType(type) && $0.isIncludedBetween(min: min, max: max)
- }
- let filter2 = orgsearchDataModel.filter {
- let firstTest = $0.listingAddress!.range(of: keyword!, options: .caseInsensitive) != nil && $0.listingType.range(of: type!, options: .caseInsensitive) != nil && $0.listingUse.range(of: use!, options: .caseInsensitive) != nil
- guard firstTest == true else { return false }
- if let price = Int($0.listingPrice ?? "0") {
- return (price > min! && price < max!) && firstTest
- }
- return false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement