Unverified Commit aeaf1bbc authored by Zach Knox's avatar Zach Knox
Browse files

Merge branch '21-filters' of git.gmu.edu:srct/whats-open-ios into 21-filters

parents 926c2323 55e518e0
......@@ -117,25 +117,35 @@ class Filters {
}
}
//TODO
// Takes in array of Facilities, separates them into those open and closed, returning a tuple of 2 arrays
private func separateOpenAndClosed(_ facilities: List<Facility>) -> (open: List<Facility>, closed: List<Facility>) {
return (List<Facility>(), List<Facility>())
let open = List<Facility>()
let closed = List<Facility>()
facilities.forEach {
Utilities.isOpen(facility: $0) ? open.append($0) : closed.append($0)
}
return (open, closed)
}
//TODO
// Sorts items in the given Facility array by name alphabetically (reverse if told)
private func sortAlphabetically(_ facilities: List<Facility>, reverse: Bool = false) -> List<Facility> {
return List<Facility>()
// Convert to a swift array because the realm sorting method crashes the list object for some reason?
var facilitiesArray = facilities.asArray()
facilitiesArray.sort { $0.facilityName < $1.facilityName }
return facilitiesArray.asRealmList()
}
//TODO
// Sorts Facilities by their given location's name, and within those sorts A->Z
private func sortByLocation(_ facilities: List<Facility>) -> List<Facility> {
return List<Facility>()
var facilitiesArray = facilities.asArray()
facilitiesArray.sort { (facility, nextFacility) in
guard let location = facility.facilityLocation else { return true }
guard let nextLocation = nextFacility.facilityLocation else { return false }
return location.building < nextLocation.building
}
return facilitiesArray.asRealmList()
}
func setShowOpen(_ to: Bool) -> Bool {
......@@ -190,3 +200,20 @@ enum SortMethod {
//We should figure out how we want to allow sorting
}
extension Array where Element: RealmCollectionValue {
func asRealmList() -> List<Element> {
return self.reduce(into: List<Element>()) { (list, element) in
list.append(element)
}
}
}
extension List {
func asArray() -> [Element] {
return self.reduce(into: [Element]()) { (array, element) in
array.append(element)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment