Skip to content

Instantly share code, notes, and snippets.

@mazz
Last active October 13, 2019 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mazz/e9fe37250b3306c18d4c943830acca59 to your computer and use it in GitHub Desktop.
Save mazz/e9fe37250b3306c18d4c943830acca59 to your computer and use it in GitHub Desktop.
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