This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Greater Than or Less Than | |
var rentPerMonth = [["rent" : 2200], ["rent" : 2350], ["rent" : 2300], ["rent" : 2490]] | |
var filteredRent = rentPerMonth.filter({ | |
$0["rent"] < 2000 | |
}) | |
print(filteredRent) |
This will display an empty array.
filter: Used for
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Select nonchanging values like neighbordhoods – Good for buttons | |
let neighborhoods: NSArray = ["Crown Heights", "Clinton Hill", "Sunset Park"] | |
let fiteredNeighborhoods = (neighborhoods as! Array).filter { $0 == "Sunset Park" } | |
print(fiteredNeighborhoods) |
containsString: Search by Keyword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Search by Keyword | |
let savedApartments = [ | |
"apt1" : "The unit comes with stainless steel appliances, a full-sized refrigerator, plenty of storage, a gas oven, a gas range, and a dishwasher.The bedroom has hardwood floors and a window that opens.", "apt2" : "you will love it", "apt3" : "So many great amenities"] | |
for (name, description) in savedApartments { | |
if description.containsString("a window that opens") { | |
print(name) | |
} | |
} |
Leave a Reply