Last active
October 13, 2019 01:00
-
-
Save mazz/e9fe37250b3306c18d4c943830acca59 to your computer and use it in GitHub Desktop.
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
let databasePool: DatabasePool = self.userService.rawDatabasePool() | |
let coursesObservation = ValueObservation.tracking { db -> [MbyCourse] in | |
var courses: [MbyCourse] = [] | |
do { | |
let mbyCourses = try MbyCourse | |
.filter(Column("orgUuid") == self.orgUuid.value) // also tried removing this filter line | |
.filter(Column("archived") == false) // also tried removing this filter line | |
.fetchAll(db) | |
courses = mbyCourses | |
} catch { | |
print("error observing courses: \(error)") | |
} | |
return courses | |
} | |
do { | |
observer = coursesObservation.start(in: databasePool, onError: { error in | |
print("courses could not be fetched: \(error)") | |
}, onChange: { [weak self] (mbyCourses: [MbyCourse]) in | |
if let strongSelf = self { | |
strongSelf.sections.value = strongSelf.coursesRefresh(refreshedCourses: mbyCourses) | |
} | |
}) | |
} catch { | |
print("courses could not be fetched: \(error)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment