mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Improve ValueObservation.trackingVaryingRegion example
This commit is contained in:
1 parent
2c3d0b1e17
commit
fea89100d9
2 files changed
+4
-2
No files matched your search
@@ -63,7 +63,8 @@ If the tracked value is computed from several database requests that are not alw
|
||||
```swift
|
||||
// An observation which does not always execute the same requests:
|
||||
let observation = ValueObservation.trackingVaryingRegion { db -> Int in
|
||||
switch try Preference.fetchOne(db)!.selection {
|
||||
let preference = try Preference.fetchOne(db) ?? .default
|
||||
switch preference.selection {
|
||||
case .food: return try Food.fetchCount(db)
|
||||
case .beverage: return try Beverage.fetchCount(db)
|
||||
}
|
||||
|
||||
@@ -5634,7 +5634,8 @@ In this case, use `ValueObservation.trackingVaryingRegion(_:)` instead:
|
||||
// An observation which tracks the 'preference', 'food' and 'beverage'
|
||||
// tables, as needed.
|
||||
let observation = ValueObservation.trackingVaryingRegion { db -> Int in
|
||||
switch try Preference.fetchOne(db)!.selection {
|
||||
let preference = try Preference.fetchOne(db) ?? .default
|
||||
switch preference.selection {
|
||||
case .food: return try Food.fetchCount(db)
|
||||
case .beverage: return try Beverage.fetchCount(db)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user