keyPath utilities for SectionBy clauses

This commit is contained in:
John Rommel Estropia
2017-09-24 10:38:17 +09:00
parent e814733ae9
commit 645034dde5
12 changed files with 207 additions and 58 deletions

View File

@@ -237,7 +237,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.queryValue(
From<TimeZone>()
.select(NSNumber.self, .count(#keyPath(TimeZone.name)))
.select(NSNumber.self, .count(\.name))
)! as Any
}
),
@@ -247,7 +247,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
return Static.timeZonesStack.queryValue(
From<TimeZone>()
.select(String.self, .attribute(#keyPath(TimeZone.abbreviation)))
.select(String.self, .attribute(\.abbreviation))
.where(format: "%K ENDSWITH[c] %@", #keyPath(TimeZone.name), "Tokyo")
)! as Any
}
@@ -260,10 +260,10 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
From<TimeZone>()
.select(
NSDictionary.self,
.attribute(#keyPath(TimeZone.name)),
.attribute(#keyPath(TimeZone.abbreviation))
.attribute(\.name),
.attribute(\.abbreviation)
)
.orderBy(.ascending(#keyPath(TimeZone.name)))
.orderBy(.ascending(\.name))
)!
}
),
@@ -275,14 +275,14 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
From<TimeZone>()
.select(
NSDictionary.self,
.count(#keyPath(TimeZone.abbreviation)),
.attribute(#keyPath(TimeZone.abbreviation))
.count(\.abbreviation),
.attribute(\.abbreviation)
)
.groupBy(#keyPath(TimeZone.abbreviation))
.groupBy(\.abbreviation)
.orderBy(
.ascending(#keyPath(TimeZone.secondsFromGMT)),
.ascending(#keyPath(TimeZone.name))
)
.ascending(\.secondsFromGMT),
.ascending(\.name)
)
)!
}
),
@@ -291,13 +291,17 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
query: { () -> Any in
return Static.timeZonesStack.queryAttributes(
From<TimeZone>(),
Select<NSDictionary>(
.count(#keyPath(TimeZone.hasDaylightSavingTime), as: "numberOfCountries"),
#keyPath(TimeZone.hasDaylightSavingTime)
),
GroupBy<TimeZone>(#keyPath(TimeZone.hasDaylightSavingTime)),
OrderBy<TimeZone>(.descending(#keyPath(TimeZone.hasDaylightSavingTime)))
From<TimeZone>()
.select(
NSDictionary.self,
.count(\.hasDaylightSavingTime, as: "numberOfCountries"),
.attribute(\.hasDaylightSavingTime)
)
.groupBy(\.hasDaylightSavingTime)
.orderBy(
.descending(\.hasDaylightSavingTime),
.ascending(\.name)
)
)!
}
)

View File

@@ -287,8 +287,8 @@ class MigrationsDemoViewController: UIViewController, ListObserver, UITableViewD
self.set(dataStack: dataStack, model: model, scrollToSelection: true)
let count = dataStack.queryValue(
From(model.entityType),
Select<Int>(.count(#keyPath(OrganismV1.dna))))!
From<NSManagedObject>(model.entityType)
.select(Int.self, .count(#keyPath(OrganismV1.dna))))!
if count > 0 {
self.setEnabled(true)