mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-21 08:59:24 +01:00
WIP
This commit is contained in:
@@ -18,9 +18,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
|
|
||||||
var window: UIWindow?
|
var window: UIWindow?
|
||||||
|
|
||||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||||
|
|
||||||
application.statusBarStyle = .LightContent
|
application.statusBarStyle = .lightContent
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,23 +23,23 @@ private struct Static {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
dataStack.beginSynchronous { (transaction) -> Void in
|
_ = dataStack.beginSynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
transaction.deleteAll(From(TimeZone))
|
transaction.deleteAll(From<TimeZone>())
|
||||||
|
|
||||||
for name in NSTimeZone.knownTimeZoneNames() {
|
for name in Foundation.TimeZone.knownTimeZoneNames {
|
||||||
|
|
||||||
let rawTimeZone = NSTimeZone(name: name)!
|
let rawTimeZone = Foundation.TimeZone(name: name)!
|
||||||
let cachedTimeZone = transaction.create(Into(TimeZone))
|
let cachedTimeZone = transaction.create(Into<TimeZone>())
|
||||||
|
|
||||||
cachedTimeZone.name = rawTimeZone.name
|
cachedTimeZone.name = rawTimeZone.name
|
||||||
cachedTimeZone.abbreviation = rawTimeZone.abbreviation ?? ""
|
cachedTimeZone.abbreviation = rawTimeZone.abbreviation ?? ""
|
||||||
cachedTimeZone.secondsFromGMT = Int32(rawTimeZone.secondsFromGMT)
|
cachedTimeZone.secondsFromGMT = Int32(rawTimeZone.secondsFromGMT)
|
||||||
cachedTimeZone.hasDaylightSavingTime = rawTimeZone.daylightSavingTime
|
cachedTimeZone.hasDaylightSavingTime = rawTimeZone.isDaylightSavingTime
|
||||||
cachedTimeZone.daylightSavingTimeOffset = rawTimeZone.daylightSavingTimeOffset
|
cachedTimeZone.daylightSavingTimeOffset = rawTimeZone.daylightSavingTimeOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.commitAndWait()
|
_ = transaction.commitAndWait()
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataStack
|
return dataStack
|
||||||
@@ -53,7 +53,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
|
|
||||||
// MARK: UIViewController
|
// MARK: UIViewController
|
||||||
|
|
||||||
override func viewDidAppear(animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
@@ -67,27 +67,27 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
let alert = UIAlertController(
|
let alert = UIAlertController(
|
||||||
title: "Fetch and Query Demo",
|
title: "Fetch and Query Demo",
|
||||||
message: "This demo shows how to execute fetches and queries.\n\nEach menu item executes and displays a preconfigured fetch/query.",
|
message: "This demo shows how to execute fetches and queries.\n\nEach menu item executes and displays a preconfigured fetch/query.",
|
||||||
preferredStyle: .Alert
|
preferredStyle: .alert
|
||||||
)
|
)
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
|
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
|
||||||
self.presentViewController(alert, animated: true, completion: nil)
|
self.present(alert, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||||
|
|
||||||
super.prepareForSegue(segue, sender: sender)
|
super.prepare(for: segue, sender: sender)
|
||||||
|
|
||||||
if let indexPath = sender as? NSIndexPath {
|
if let indexPath = sender as? IndexPath {
|
||||||
|
|
||||||
switch segue.destinationViewController {
|
switch segue.destinationViewController {
|
||||||
|
|
||||||
case let controller as FetchingResultsViewController:
|
case let controller as FetchingResultsViewController:
|
||||||
let item = self.fetchingItems[indexPath.row]
|
let item = self.fetchingItems[indexPath.row]
|
||||||
controller.setTimeZones(item.fetch(), title: item.title)
|
controller.set(timeZones: item.fetch(), title: item.title)
|
||||||
|
|
||||||
case let controller as QueryingResultsViewController:
|
case let controller as QueryingResultsViewController:
|
||||||
let item = self.queryingItems[indexPath.row]
|
let item = self.queryingItems[indexPath.row]
|
||||||
controller.setValue(item.query(), title: item.title)
|
controller.set(value: item.query(), title: item.title)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
@@ -98,7 +98,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
|
|
||||||
// MARK: UITableViewDataSource
|
// MARK: UITableViewDataSource
|
||||||
|
|
||||||
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
||||||
switch self.segmentedControl?.selectedSegmentIndex {
|
switch self.segmentedControl?.selectedSegmentIndex {
|
||||||
|
|
||||||
@@ -113,9 +113,9 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
||||||
let cell = tableView.dequeueReusableCellWithIdentifier("UITableViewCell")!
|
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell")!
|
||||||
|
|
||||||
switch self.segmentedControl?.selectedSegmentIndex {
|
switch self.segmentedControl?.selectedSegmentIndex {
|
||||||
|
|
||||||
@@ -135,17 +135,17 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
|
|
||||||
// MARK: UITableViewDelegate
|
// MARK: UITableViewDelegate
|
||||||
|
|
||||||
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
|
||||||
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
tableView.deselectRow(at: indexPath, animated: true)
|
||||||
|
|
||||||
switch self.segmentedControl?.selectedSegmentIndex {
|
switch self.segmentedControl?.selectedSegmentIndex {
|
||||||
|
|
||||||
case Section.Fetching.rawValue?:
|
case Section.Fetching.rawValue?:
|
||||||
self.performSegueWithIdentifier("FetchingResultsViewController", sender: indexPath)
|
self.performSegue(withIdentifier: "FetchingResultsViewController", sender: indexPath)
|
||||||
|
|
||||||
case Section.Querying.rawValue?:
|
case Section.Querying.rawValue?:
|
||||||
self.performSegueWithIdentifier("QueryingResultsViewController", sender: indexPath)
|
self.performSegue(withIdentifier: "QueryingResultsViewController", sender: indexPath)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
@@ -167,7 +167,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
fetch: { () -> [TimeZone] in
|
fetch: { () -> [TimeZone] in
|
||||||
|
|
||||||
return Static.timeZonesStack.fetchAll(
|
return Static.timeZonesStack.fetchAll(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
OrderBy(.ascending("name"))
|
OrderBy(.ascending("name"))
|
||||||
)!
|
)!
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
fetch: { () -> [TimeZone] in
|
fetch: { () -> [TimeZone] in
|
||||||
|
|
||||||
return Static.timeZonesStack.fetchAll(
|
return Static.timeZonesStack.fetchAll(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
Where("%K BEGINSWITH[c] %@", "name", "Asia"),
|
Where("%K BEGINSWITH[c] %@", "name", "Asia"),
|
||||||
OrderBy(.ascending("secondsFromGMT"))
|
OrderBy(.ascending("secondsFromGMT"))
|
||||||
)!
|
)!
|
||||||
@@ -188,7 +188,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
fetch: { () -> [TimeZone] in
|
fetch: { () -> [TimeZone] in
|
||||||
|
|
||||||
return Static.timeZonesStack.fetchAll(
|
return Static.timeZonesStack.fetchAll(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
Where("%K BEGINSWITH[c] %@", "name", "America")
|
Where("%K BEGINSWITH[c] %@", "name", "America")
|
||||||
|| Where("%K BEGINSWITH[c] %@", "name", "Europe"),
|
|| Where("%K BEGINSWITH[c] %@", "name", "Europe"),
|
||||||
OrderBy(.ascending("secondsFromGMT"))
|
OrderBy(.ascending("secondsFromGMT"))
|
||||||
@@ -200,7 +200,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
fetch: { () -> [TimeZone] in
|
fetch: { () -> [TimeZone] in
|
||||||
|
|
||||||
return Static.timeZonesStack.fetchAll(
|
return Static.timeZonesStack.fetchAll(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
!Where("%K BEGINSWITH[c] %@", "name", "America"),
|
!Where("%K BEGINSWITH[c] %@", "name", "America"),
|
||||||
OrderBy(.ascending("secondsFromGMT"))
|
OrderBy(.ascending("secondsFromGMT"))
|
||||||
)!
|
)!
|
||||||
@@ -211,7 +211,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
fetch: { () -> [TimeZone] in
|
fetch: { () -> [TimeZone] in
|
||||||
|
|
||||||
return Static.timeZonesStack.fetchAll(
|
return Static.timeZonesStack.fetchAll(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
Where("hasDaylightSavingTime", isEqualTo: true),
|
Where("hasDaylightSavingTime", isEqualTo: true),
|
||||||
OrderBy(.ascending("name"))
|
OrderBy(.ascending("name"))
|
||||||
)!
|
)!
|
||||||
@@ -225,8 +225,8 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
query: { () -> AnyObject in
|
query: { () -> AnyObject in
|
||||||
|
|
||||||
return Static.timeZonesStack.queryValue(
|
return Static.timeZonesStack.queryValue(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
Select<NSNumber>(.Count("name"))
|
Select<NSNumber>(.count("name"))
|
||||||
)!
|
)!
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
@@ -235,7 +235,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
query: { () -> AnyObject in
|
query: { () -> AnyObject in
|
||||||
|
|
||||||
return Static.timeZonesStack.queryValue(
|
return Static.timeZonesStack.queryValue(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
Select<String>("abbreviation"),
|
Select<String>("abbreviation"),
|
||||||
Where("%K ENDSWITH[c] %@", "name", "Tokyo")
|
Where("%K ENDSWITH[c] %@", "name", "Tokyo")
|
||||||
)!
|
)!
|
||||||
@@ -246,7 +246,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
query: { () -> AnyObject in
|
query: { () -> AnyObject in
|
||||||
|
|
||||||
return Static.timeZonesStack.queryAttributes(
|
return Static.timeZonesStack.queryAttributes(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
Select<NSDictionary>("name", "abbreviation"),
|
Select<NSDictionary>("name", "abbreviation"),
|
||||||
OrderBy(.ascending("name"))
|
OrderBy(.ascending("name"))
|
||||||
)!
|
)!
|
||||||
@@ -257,8 +257,8 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
query: { () -> AnyObject in
|
query: { () -> AnyObject in
|
||||||
|
|
||||||
return Static.timeZonesStack.queryAttributes(
|
return Static.timeZonesStack.queryAttributes(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
Select<NSDictionary>(.Count("abbreviation"), "abbreviation"),
|
Select<NSDictionary>(.count("abbreviation"), "abbreviation"),
|
||||||
GroupBy("abbreviation"),
|
GroupBy("abbreviation"),
|
||||||
OrderBy(.ascending("secondsFromGMT"), .ascending("name"))
|
OrderBy(.ascending("secondsFromGMT"), .ascending("name"))
|
||||||
)!
|
)!
|
||||||
@@ -269,9 +269,9 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
|
|||||||
query: { () -> AnyObject in
|
query: { () -> AnyObject in
|
||||||
|
|
||||||
return Static.timeZonesStack.queryAttributes(
|
return Static.timeZonesStack.queryAttributes(
|
||||||
From(TimeZone),
|
From<TimeZone>(),
|
||||||
Select<NSDictionary>(
|
Select<NSDictionary>(
|
||||||
.Count("hasDaylightSavingTime", As: "numberOfCountries"),
|
.count("hasDaylightSavingTime", As: "numberOfCountries"),
|
||||||
"hasDaylightSavingTime"
|
"hasDaylightSavingTime"
|
||||||
),
|
),
|
||||||
GroupBy("hasDaylightSavingTime"),
|
GroupBy("hasDaylightSavingTime"),
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class FetchingResultsViewController: UITableViewController {
|
|||||||
|
|
||||||
// MARK: Public
|
// MARK: Public
|
||||||
|
|
||||||
func setTimeZones(timeZones: [TimeZone]?, title: String) {
|
func set(timeZones: [TimeZone]?, title: String) {
|
||||||
|
|
||||||
self.timeZones += timeZones ?? []
|
self.timeZones += timeZones ?? []
|
||||||
self.sectionTitle = title
|
self.sectionTitle = title
|
||||||
@@ -36,14 +36,14 @@ class FetchingResultsViewController: UITableViewController {
|
|||||||
|
|
||||||
// MARK: UITableViewDataSource
|
// MARK: UITableViewDataSource
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
||||||
return self.timeZones.count
|
return self.timeZones.count
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
||||||
let cell = tableView.dequeueReusableCellWithIdentifier("UITableViewCell", forIndexPath: indexPath)
|
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
|
||||||
|
|
||||||
let timeZone = self.timeZones[indexPath.row]
|
let timeZone = self.timeZones[indexPath.row]
|
||||||
cell.textLabel?.text = timeZone.name
|
cell.textLabel?.text = timeZone.name
|
||||||
@@ -55,7 +55,7 @@ class FetchingResultsViewController: UITableViewController {
|
|||||||
|
|
||||||
// MARK: UITableViewDelegate
|
// MARK: UITableViewDelegate
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||||
|
|
||||||
return self.sectionTitle
|
return self.sectionTitle
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class QueryingResultsViewController: UITableViewController {
|
|||||||
|
|
||||||
// MARK: Public
|
// MARK: Public
|
||||||
|
|
||||||
func setValue(value: AnyObject?, title: String) {
|
func set(value: AnyObject?, title: String) {
|
||||||
|
|
||||||
switch value {
|
switch value {
|
||||||
|
|
||||||
@@ -55,14 +55,14 @@ class QueryingResultsViewController: UITableViewController {
|
|||||||
|
|
||||||
// MARK: UITableViewDataSource
|
// MARK: UITableViewDataSource
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
||||||
return self.values.count
|
return self.values.count
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
||||||
let cell = tableView.dequeueReusableCellWithIdentifier("UITableViewCell", forIndexPath: indexPath)
|
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
|
||||||
|
|
||||||
let value = self.values[indexPath.row]
|
let value = self.values[indexPath.row]
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ class QueryingResultsViewController: UITableViewController {
|
|||||||
|
|
||||||
// MARK: UITableViewDelegate
|
// MARK: UITableViewDelegate
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||||
|
|
||||||
return self.sectionTitle
|
return self.sectionTitle
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ private struct Static {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return CoreStore.monitorSectionedList(
|
return CoreStore.monitorSectionedList(
|
||||||
From(Palette),
|
From<Palette>(),
|
||||||
SectionBy("colorName"),
|
SectionBy("colorName"),
|
||||||
OrderBy(.ascending("hue"))
|
OrderBy(.ascending("hue"))
|
||||||
)
|
)
|
||||||
@@ -88,7 +88,7 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
navigationItem.leftBarButtonItems = [
|
navigationItem.leftBarButtonItems = [
|
||||||
self.editButtonItem(),
|
self.editButtonItem(),
|
||||||
UIBarButtonItem(
|
UIBarButtonItem(
|
||||||
barButtonSystemItem: .Trash,
|
barButtonSystemItem: .trash,
|
||||||
target: self,
|
target: self,
|
||||||
action: #selector(self.resetBarButtonItemTouched(_:))
|
action: #selector(self.resetBarButtonItemTouched(_:))
|
||||||
)
|
)
|
||||||
@@ -96,13 +96,13 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
|
|
||||||
let filterBarButton = UIBarButtonItem(
|
let filterBarButton = UIBarButtonItem(
|
||||||
title: Static.filter.rawValue,
|
title: Static.filter.rawValue,
|
||||||
style: .Plain,
|
style: .plain,
|
||||||
target: self,
|
target: self,
|
||||||
action: #selector(self.filterBarButtonItemTouched(_:))
|
action: #selector(self.filterBarButtonItemTouched(_:))
|
||||||
)
|
)
|
||||||
navigationItem.rightBarButtonItems = [
|
navigationItem.rightBarButtonItems = [
|
||||||
UIBarButtonItem(
|
UIBarButtonItem(
|
||||||
barButtonSystemItem: .Add,
|
barButtonSystemItem: .add,
|
||||||
target: self,
|
target: self,
|
||||||
action: #selector(self.addBarButtonItemTouched(_:))
|
action: #selector(self.addBarButtonItemTouched(_:))
|
||||||
),
|
),
|
||||||
@@ -112,12 +112,12 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
|
|
||||||
Static.palettes.addObserver(self)
|
Static.palettes.addObserver(self)
|
||||||
|
|
||||||
self.setTableEnabled(!Static.palettes.isPendingRefetch)
|
self.setTable(enabled: !Static.palettes.isPendingRefetch)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||||
|
|
||||||
super.prepareForSegue(segue, sender: sender)
|
super.prepare(for: segue, sender: sender)
|
||||||
|
|
||||||
switch (segue.identifier, segue.destinationViewController, sender) {
|
switch (segue.identifier, segue.destinationViewController, sender) {
|
||||||
|
|
||||||
@@ -132,19 +132,19 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
|
|
||||||
// MARK: UITableViewDataSource
|
// MARK: UITableViewDataSource
|
||||||
|
|
||||||
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
|
||||||
return Static.palettes.numberOfSections()
|
return Static.palettes.numberOfSections()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
||||||
return Static.palettes.numberOfObjectsInSection(section)
|
return Static.palettes.numberOfObjectsInSection(section)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
||||||
let cell = tableView.dequeueReusableCellWithIdentifier("PaletteTableViewCell") as! PaletteTableViewCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: "PaletteTableViewCell") as! PaletteTableViewCell
|
||||||
|
|
||||||
let palette = Static.palettes[indexPath]
|
let palette = Static.palettes[indexPath]
|
||||||
cell.colorView?.backgroundColor = palette.color
|
cell.colorView?.backgroundColor = palette.color
|
||||||
@@ -156,21 +156,21 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
|
|
||||||
// MARK: UITableViewDelegate
|
// MARK: UITableViewDelegate
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
|
||||||
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
tableView.deselectRow(at: indexPath, animated: true)
|
||||||
|
|
||||||
self.performSegueWithIdentifier(
|
self.performSegue(
|
||||||
"ObjectObserverDemoViewController",
|
withIdentifier: "ObjectObserverDemoViewController",
|
||||||
sender: Static.palettes[indexPath]
|
sender: Static.palettes[indexPath]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
|
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
|
||||||
|
|
||||||
switch editingStyle {
|
switch editingStyle {
|
||||||
|
|
||||||
case .Delete:
|
case .delete:
|
||||||
let palette = Static.palettes[indexPath]
|
let palette = Static.palettes[indexPath]
|
||||||
CoreStore.beginAsynchronous{ (transaction) -> Void in
|
CoreStore.beginAsynchronous{ (transaction) -> Void in
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||||
|
|
||||||
return Static.palettes.sectionInfoAtIndex(section).name
|
return Static.palettes.sectionInfoAtIndex(section).name
|
||||||
}
|
}
|
||||||
@@ -191,44 +191,44 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
|
|
||||||
// MARK: ListObserver
|
// MARK: ListObserver
|
||||||
|
|
||||||
func listMonitorWillChange(monitor: ListMonitor<Palette>) {
|
func listMonitorWillChange(_ monitor: ListMonitor<Palette>) {
|
||||||
|
|
||||||
self.tableView.beginUpdates()
|
self.tableView.beginUpdates()
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMonitorDidChange(monitor: ListMonitor<Palette>) {
|
func listMonitorDidChange(_ monitor: ListMonitor<Palette>) {
|
||||||
|
|
||||||
self.tableView.endUpdates()
|
self.tableView.endUpdates()
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMonitorWillRefetch(monitor: ListMonitor<Palette>) {
|
func listMonitorWillRefetch(monitor: ListMonitor<Palette>) {
|
||||||
|
|
||||||
self.setTableEnabled(false)
|
self.setTable(enabled: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMonitorDidRefetch(monitor: ListMonitor<Palette>) {
|
func listMonitorDidRefetch(monitor: ListMonitor<Palette>) {
|
||||||
|
|
||||||
self.filterBarButton?.title = Static.filter.rawValue
|
self.filterBarButton?.title = Static.filter.rawValue
|
||||||
self.tableView.reloadData()
|
self.tableView.reloadData()
|
||||||
self.setTableEnabled(true)
|
self.setTable(enabled: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: ListObjectObserver
|
// MARK: ListObjectObserver
|
||||||
|
|
||||||
func listMonitor(monitor: ListMonitor<Palette>, didInsertObject object: Palette, toIndexPath indexPath: NSIndexPath) {
|
func listMonitor(_ monitor: ListMonitor<Palette>, didInsertObject object: Palette, toIndexPath indexPath: IndexPath) {
|
||||||
|
|
||||||
self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
|
self.tableView.insertRows(at: [indexPath], with: .automatic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMonitor(monitor: ListMonitor<Palette>, didDeleteObject object: Palette, fromIndexPath indexPath: NSIndexPath) {
|
func listMonitor(_ monitor: ListMonitor<Palette>, didDeleteObject object: Palette, fromIndexPath indexPath: IndexPath) {
|
||||||
|
|
||||||
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
|
self.tableView.deleteRows(at: [indexPath], with: .automatic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMonitor(monitor: ListMonitor<Palette>, didUpdateObject object: Palette, atIndexPath indexPath: NSIndexPath) {
|
func listMonitor(_ monitor: ListMonitor<Palette>, didUpdateObject object: Palette, atIndexPath indexPath: IndexPath) {
|
||||||
|
|
||||||
if let cell = self.tableView.cellForRowAtIndexPath(indexPath) as? PaletteTableViewCell {
|
if let cell = self.tableView.cellForRow(at: indexPath) as? PaletteTableViewCell {
|
||||||
|
|
||||||
let palette = Static.palettes[indexPath]
|
let palette = Static.palettes[indexPath]
|
||||||
cell.colorView?.backgroundColor = palette.color
|
cell.colorView?.backgroundColor = palette.color
|
||||||
@@ -236,23 +236,24 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMonitor(monitor: ListMonitor<Palette>, didMoveObject object: Palette, fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
|
func listMonitor(_ monitor: ListMonitor<Palette>, didMoveObject object: Palette, fromIndexPath: IndexPath, toIndexPath: IndexPath) {
|
||||||
|
|
||||||
self.tableView.deleteRowsAtIndexPaths([fromIndexPath], withRowAnimation: .Automatic)
|
self.tableView.deleteRows(at: [fromIndexPath], with: .automatic)
|
||||||
self.tableView.insertRowsAtIndexPaths([toIndexPath], withRowAnimation: .Automatic)
|
self.tableView.insertRows(at: [toIndexPath], with: .automatic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: ListSectionObserver
|
// MARK: ListSectionObserver
|
||||||
|
|
||||||
func listMonitor(monitor: ListMonitor<Palette>, didInsertSection sectionInfo: NSFetchedResultsSectionInfo, toSectionIndex sectionIndex: Int) {
|
func listMonitor(_ monitor: ListMonitor<Palette>, didInsertSection sectionInfo: NSFetchedResultsSectionInfo, toSectionIndex sectionIndex: Int) {
|
||||||
|
|
||||||
self.tableView.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Automatic)
|
self.tableView.insertSections(IndexSet(integer: sectionIndex), with: .automatic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listMonitor(monitor: ListMonitor<Palette>, didDeleteSection sectionInfo: NSFetchedResultsSectionInfo, fromSectionIndex sectionIndex: Int) {
|
|
||||||
|
|
||||||
self.tableView.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Automatic)
|
func listMonitor(_ monitor: ListMonitor<Palette>, didDeleteSection sectionInfo: NSFetchedResultsSectionInfo, fromSectionIndex sectionIndex: Int) {
|
||||||
|
|
||||||
|
self.tableView.deleteSections(IndexSet(integer: sectionIndex), with: .automatic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -260,43 +261,43 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
|
|
||||||
private var filterBarButton: UIBarButtonItem?
|
private var filterBarButton: UIBarButtonItem?
|
||||||
|
|
||||||
@IBAction private dynamic func resetBarButtonItemTouched(sender: AnyObject?) {
|
@IBAction private dynamic func resetBarButtonItemTouched(_ sender: AnyObject?) {
|
||||||
|
|
||||||
CoreStore.beginAsynchronous { (transaction) -> Void in
|
CoreStore.beginAsynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
transaction.deleteAll(From(Palette))
|
transaction.deleteAll(From<Palette>())
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction private dynamic func filterBarButtonItemTouched(sender: AnyObject?) {
|
@IBAction private dynamic func filterBarButtonItemTouched(_ sender: AnyObject?) {
|
||||||
|
|
||||||
Static.filter = Static.filter.next()
|
Static.filter = Static.filter.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction private dynamic func addBarButtonItemTouched(sender: AnyObject?) {
|
@IBAction private dynamic func addBarButtonItemTouched(_ sender: AnyObject?) {
|
||||||
|
|
||||||
CoreStore.beginAsynchronous { (transaction) -> Void in
|
CoreStore.beginAsynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
let palette = transaction.create(Into(Palette))
|
let palette = transaction.create(Into<Palette>())
|
||||||
palette.setInitialValues()
|
palette.setInitialValues()
|
||||||
|
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setTableEnabled(enabled: Bool) {
|
private func setTable(enabled: Bool) {
|
||||||
|
|
||||||
UIView.animateWithDuration(
|
UIView.animate(
|
||||||
0.2,
|
withDuration: 0.2,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
options: .BeginFromCurrentState,
|
options: .beginFromCurrentState,
|
||||||
animations: { () -> Void in
|
animations: { () -> Void in
|
||||||
|
|
||||||
if let tableView = self.tableView {
|
if let tableView = self.tableView {
|
||||||
|
|
||||||
tableView.alpha = enabled ? 1.0 : 0.5
|
tableView.alpha = enabled ? 1.0 : 0.5
|
||||||
tableView.userInteractionEnabled = enabled
|
tableView.isUserInteractionEnabled = enabled
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
completion: nil
|
completion: nil
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
|
|||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
|
|
||||||
if let palette = CoreStore.fetchOne(From(Palette), OrderBy(.ascending("hue"))) {
|
if let palette = CoreStore.fetchOne(From<Palette>(), OrderBy(.ascending("hue"))) {
|
||||||
|
|
||||||
self.monitor = CoreStore.monitorObject(palette)
|
self.monitor = CoreStore.monitorObject(palette)
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
|
|||||||
transaction.commitAndWait()
|
transaction.commitAndWait()
|
||||||
}
|
}
|
||||||
|
|
||||||
let palette = CoreStore.fetchOne(From(Palette), OrderBy(.ascending("hue")))!
|
let palette = CoreStore.fetchOne(From<Palette>(), OrderBy(.ascending("hue")))!
|
||||||
self.monitor = CoreStore.monitorObject(palette)
|
self.monitor = CoreStore.monitorObject(palette)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,24 +85,24 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
|
|||||||
|
|
||||||
// MARK: ObjectObserver
|
// MARK: ObjectObserver
|
||||||
|
|
||||||
func objectMonitor(monitor: ObjectMonitor<Palette>, didUpdateObject object: Palette, changedPersistentKeys: Set<KeyPath>) {
|
func objectMonitor(_ monitor: ObjectMonitor<Palette>, didUpdateObject object: Palette, changedPersistentKeys: Set<KeyPath>) {
|
||||||
|
|
||||||
self.reloadPaletteInfo(object, changedKeys: changedPersistentKeys)
|
self.reloadPaletteInfo(object, changedKeys: changedPersistentKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
func objectMonitor(monitor: ObjectMonitor<Palette>, didDeleteObject object: Palette) {
|
func objectMonitor(_ monitor: ObjectMonitor<Palette>, didDeleteObject object: Palette) {
|
||||||
|
|
||||||
self.navigationItem.rightBarButtonItem?.enabled = false
|
self.navigationItem.rightBarButtonItem?.isEnabled = false
|
||||||
|
|
||||||
self.colorNameLabel?.alpha = 0.3
|
self.colorNameLabel?.alpha = 0.3
|
||||||
self.colorView?.alpha = 0.3
|
self.colorView?.alpha = 0.3
|
||||||
|
|
||||||
self.hsbLabel?.text = "Deleted"
|
self.hsbLabel?.text = "Deleted"
|
||||||
self.hsbLabel?.textColor = UIColor.redColor()
|
self.hsbLabel?.textColor = UIColor.red()
|
||||||
|
|
||||||
self.hueSlider?.enabled = false
|
self.hueSlider?.isEnabled = false
|
||||||
self.saturationSlider?.enabled = false
|
self.saturationSlider?.isEnabled = false
|
||||||
self.brightnessSlider?.enabled = false
|
self.brightnessSlider?.isEnabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reloadPaletteInfo(palette: Palette, changedKeys: Set<String>?) {
|
func reloadPaletteInfo(_ palette: Palette, changedKeys: Set<String>?) {
|
||||||
|
|
||||||
self.colorNameLabel?.text = palette.colorName
|
self.colorNameLabel?.text = palette.colorName
|
||||||
|
|
||||||
|
|||||||
@@ -15,16 +15,16 @@ class ObserversViewController: UIViewController {
|
|||||||
|
|
||||||
// MARK: UIViewController
|
// MARK: UIViewController
|
||||||
|
|
||||||
override func viewDidAppear(animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
let alert = UIAlertController(
|
let alert = UIAlertController(
|
||||||
title: "Observers Demo",
|
title: "Observers Demo",
|
||||||
message: "This demo shows how to observe changes to a list of objects. The top and bottom view controllers both observe a single shared \"ListMonitor\" instance.\n\nTap on a row to see how to observe changes made to a single object using a \"ObjectMonitor\".",
|
message: "This demo shows how to observe changes to a list of objects. The top and bottom view controllers both observe a single shared \"ListMonitor\" instance.\n\nTap on a row to see how to observe changes made to a single object using a \"ObjectMonitor\".",
|
||||||
preferredStyle: .Alert
|
preferredStyle: .alert
|
||||||
)
|
)
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
|
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
|
||||||
self.presentViewController(alert, animated: true, completion: nil)
|
self.present(alert, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,23 +34,23 @@ class CustomLoggerViewController: UIViewController, CoreStoreLogger {
|
|||||||
CoreStore.logger = self
|
CoreStore.logger = self
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
let alert = UIAlertController(
|
let alert = UIAlertController(
|
||||||
title: "Logger Demo",
|
title: "Logger Demo",
|
||||||
message: "This demo shows how to plug-in any logging framework to CoreStore.\n\nThe view controller implements CoreStoreLogger and appends all logs to the text view.",
|
message: "This demo shows how to plug-in any logging framework to CoreStore.\n\nThe view controller implements CoreStoreLogger and appends all logs to the text view.",
|
||||||
preferredStyle: .Alert
|
preferredStyle: .alert
|
||||||
)
|
)
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
|
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
|
||||||
self.presentViewController(alert, animated: true, completion: nil)
|
self.present(alert, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: CoreStoreLogger
|
// MARK: CoreStoreLogger
|
||||||
|
|
||||||
func log(level level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
func log(level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||||
|
|
||||||
GCDQueue.main.async { [weak self] in
|
GCDQueue.main.async { [weak self] in
|
||||||
|
|
||||||
@@ -62,19 +62,19 @@ class CustomLoggerViewController: UIViewController, CoreStoreLogger {
|
|||||||
case .warning: levelString = "Warning"
|
case .warning: levelString = "Warning"
|
||||||
case .fatal: levelString = "Fatal"
|
case .fatal: levelString = "Fatal"
|
||||||
}
|
}
|
||||||
self?.textView?.insertText("\((fileName.stringValue as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Log:\(levelString)] \(message)\n\n")
|
self?.textView?.insertText("\((String(fileName) as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Log:\(levelString)] \(message)\n\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func log(error error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
func log(error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||||
|
|
||||||
GCDQueue.main.async { [weak self] in
|
GCDQueue.main.async { [weak self] in
|
||||||
|
|
||||||
self?.textView?.insertText("\((fileName.stringValue as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Error] \(message): \(error)\n\n")
|
self?.textView?.insertText("\((String(fileName) as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Error] \(message): \(error)\n\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assert(@autoclosure condition: () -> Bool, @autoclosure message: () -> String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
func assert(_ condition: @autoclosure () -> Bool, message: @autoclosure () -> String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||||
|
|
||||||
if condition() {
|
if condition() {
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ class CustomLoggerViewController: UIViewController, CoreStoreLogger {
|
|||||||
let messageString = message()
|
let messageString = message()
|
||||||
GCDQueue.main.async { [weak self] in
|
GCDQueue.main.async { [weak self] in
|
||||||
|
|
||||||
self?.textView?.insertText("\((fileName.stringValue as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Assert] \(messageString)\n\n")
|
self?.textView?.insertText("\((String(fileName) as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Assert] \(messageString)\n\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ class CustomLoggerViewController: UIViewController, CoreStoreLogger {
|
|||||||
case 0?:
|
case 0?:
|
||||||
self.dataStack.beginAsynchronous { (transaction) -> Void in
|
self.dataStack.beginAsynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
transaction.create(Into(Palette))
|
_ = transaction.create(Into<Palette>())
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1?:
|
case 1?:
|
||||||
|
|||||||
@@ -22,28 +22,28 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
|
|
||||||
if let segmentedControl = self.segmentedControl {
|
if let segmentedControl = self.segmentedControl {
|
||||||
|
|
||||||
for (index, model) in self.models.enumerate() {
|
for (index, model) in self.models.enumerated() {
|
||||||
|
|
||||||
segmentedControl.setTitle(
|
segmentedControl.setTitle(
|
||||||
model.label,
|
model.label,
|
||||||
forSegmentAtIndex: index
|
forSegmentAt: index
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.setDataStack(nil, model: nil, scrollToSelection: false)
|
self.set(dataStack: nil, model: nil, scrollToSelection: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
let alert = UIAlertController(
|
let alert = UIAlertController(
|
||||||
title: "Migrations Demo",
|
title: "Migrations Demo",
|
||||||
message: "This demo shows how to run progressive migrations and how to support multiple model versions in a single project.\n\nThe persistent store contains 10000 organisms, which gain/lose properties when the migration evolves/devolves them.\n\nYou can use the \"mutate\" button to change an organism's properties then migrate to a different model to see how its value gets affected.",
|
message: "This demo shows how to run progressive migrations and how to support multiple model versions in a single project.\n\nThe persistent store contains 10000 organisms, which gain/lose properties when the migration evolves/devolves them.\n\nYou can use the \"mutate\" button to change an organism's properties then migrate to a different model to see how its value gets affected.",
|
||||||
preferredStyle: .Alert
|
preferredStyle: .alert
|
||||||
)
|
)
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
|
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
|
||||||
self.presentViewController(alert, animated: true, completion: nil)
|
self.present(alert, animated: true, completion: nil)
|
||||||
|
|
||||||
|
|
||||||
let modelMetadata = withExtendedLifetime(DataStack(modelName: "MigrationDemo")) {
|
let modelMetadata = withExtendedLifetime(DataStack(modelName: "MigrationDemo")) {
|
||||||
@@ -113,13 +113,13 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
return self._dataStack
|
return self._dataStack
|
||||||
}
|
}
|
||||||
|
|
||||||
private var _lastSelectedIndexPath: NSIndexPath?
|
private var _lastSelectedIndexPath: IndexPath?
|
||||||
private var lastSelectedIndexPath: NSIndexPath? {
|
private var lastSelectedIndexPath: IndexPath? {
|
||||||
|
|
||||||
return self._lastSelectedIndexPath
|
return self._lastSelectedIndexPath
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setSelectedIndexPath(indexPath: NSIndexPath, scrollToSelection: Bool) {
|
private func setSelectedIndexPath(_ indexPath: IndexPath, scrollToSelection: Bool) {
|
||||||
|
|
||||||
self._lastSelectedIndexPath = indexPath
|
self._lastSelectedIndexPath = indexPath
|
||||||
self.updateDisplay(reloadData: false, scrollToSelection: scrollToSelection, animated: true)
|
self.updateDisplay(reloadData: false, scrollToSelection: scrollToSelection, animated: true)
|
||||||
@@ -142,14 +142,14 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
self.selectModelVersion(self.models[index])
|
self.selectModelVersion(self.models[index])
|
||||||
}
|
}
|
||||||
|
|
||||||
private func selectModelVersion(model: ModelMetadata) {
|
private func selectModelVersion(_ model: ModelMetadata) {
|
||||||
|
|
||||||
if self.dataStack?.modelVersion == model.version {
|
if self.dataStack?.modelVersion == model.version {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setDataStack(nil, model: nil, scrollToSelection: false) // explicitly trigger NSPersistentStore cleanup by deallocating the stack
|
self.set(dataStack: nil, model: nil, scrollToSelection: false) // explicitly trigger NSPersistentStore cleanup by deallocating the stack
|
||||||
|
|
||||||
let dataStack = DataStack(
|
let dataStack = DataStack(
|
||||||
modelName: "MigrationDemo",
|
modelName: "MigrationDemo",
|
||||||
@@ -172,11 +172,11 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setDataStack(dataStack, model: model, scrollToSelection: true)
|
self.set(dataStack: dataStack, model: model, scrollToSelection: true)
|
||||||
|
|
||||||
let count = dataStack.queryValue(
|
let count = dataStack.queryValue(
|
||||||
From(model.entityType),
|
From(model.entityType),
|
||||||
Select<Int>(.Count("dna"))
|
Select<Int>(.count("dna"))
|
||||||
)
|
)
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
|
|
||||||
@@ -218,36 +218,36 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setEnabled(enabled: Bool) {
|
private func setEnabled(_ enabled: Bool) {
|
||||||
|
|
||||||
UIView.animateWithDuration(
|
UIView.animate(
|
||||||
0.2,
|
withDuration: 0.2,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
options: .BeginFromCurrentState,
|
options: .beginFromCurrentState,
|
||||||
animations: { () -> Void in
|
animations: { () -> Void in
|
||||||
|
|
||||||
let navigationItem = self.navigationItem
|
let navigationItem = self.navigationItem
|
||||||
navigationItem.leftBarButtonItem?.enabled = enabled
|
navigationItem.leftBarButtonItem?.isEnabled = enabled
|
||||||
navigationItem.rightBarButtonItem?.enabled = enabled
|
navigationItem.rightBarButtonItem?.isEnabled = enabled
|
||||||
navigationItem.hidesBackButton = !enabled
|
navigationItem.hidesBackButton = !enabled
|
||||||
|
|
||||||
self.segmentedControl?.enabled = enabled
|
self.segmentedControl?.isEnabled = enabled
|
||||||
|
|
||||||
if let tableView = self.tableView {
|
if let tableView = self.tableView {
|
||||||
|
|
||||||
tableView.alpha = enabled ? 1.0 : 0.5
|
tableView.alpha = enabled ? 1.0 : 0.5
|
||||||
tableView.userInteractionEnabled = enabled
|
tableView.isUserInteractionEnabled = enabled
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
completion: nil
|
completion: nil
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setDataStack(dataStack: DataStack?, model: ModelMetadata?, scrollToSelection: Bool) {
|
private func set(dataStack: DataStack?, model: ModelMetadata?, scrollToSelection: Bool) {
|
||||||
|
|
||||||
if let dataStack = dataStack, let model = model {
|
if let dataStack = dataStack, let model = model {
|
||||||
|
|
||||||
self.segmentedControl?.selectedSegmentIndex = self.models.map { $0.version }.indexOf(model.version)!
|
self.segmentedControl?.selectedSegmentIndex = self.models.map { $0.version }.index(of: model.version)!
|
||||||
|
|
||||||
self._dataStack = dataStack
|
self._dataStack = dataStack
|
||||||
let listMonitor = dataStack.monitorList(From(model.entityType), OrderBy(.descending("dna")))
|
let listMonitor = dataStack.monitorList(From(model.entityType), OrderBy(.descending("dna")))
|
||||||
@@ -258,7 +258,7 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
|
|
||||||
if listMonitor.numberOfObjectsInSection(0) > 0 {
|
if listMonitor.numberOfObjectsInSection(0) > 0 {
|
||||||
|
|
||||||
self.setSelectedIndexPath(NSIndexPath(forRow: 0, inSection: 0), scrollToSelection: true)
|
self.setSelectedIndexPath(IndexPath(row: 0, section: 0), scrollToSelection: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,14 +272,14 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
self.updateDisplay(reloadData: true, scrollToSelection: scrollToSelection, animated: false)
|
self.updateDisplay(reloadData: true, scrollToSelection: scrollToSelection, animated: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func reloadTableHeaderWithProgress(progress: NSProgress) {
|
private func reloadTableHeaderWithProgress(_ progress: Progress) {
|
||||||
|
|
||||||
self.progressView?.setProgress(Float(progress.fractionCompleted), animated: true)
|
self.progressView?.setProgress(Float(progress.fractionCompleted), animated: true)
|
||||||
self.titleLabel?.text = "Migrating: \(progress.localizedDescription)"
|
self.titleLabel?.text = "Migrating: \(progress.localizedDescription)"
|
||||||
self.organismLabel?.text = "Progressive step \(progress.localizedAdditionalDescription)"
|
self.organismLabel?.text = "Progressive step \(progress.localizedAdditionalDescription)"
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateDisplay(reloadData reloadData: Bool, scrollToSelection: Bool, animated: Bool) {
|
private func updateDisplay(reloadData: Bool, scrollToSelection: Bool, animated: Bool) {
|
||||||
|
|
||||||
var lines = [String]()
|
var lines = [String]()
|
||||||
var organismType = ""
|
var organismType = ""
|
||||||
@@ -287,14 +287,14 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
|
|
||||||
for property in organism.entity.properties {
|
for property in organism.entity.properties {
|
||||||
|
|
||||||
let value: AnyObject = organism.valueForKey(property.name) ?? NSNull()
|
let value: AnyObject = organism.value(forKey: property.name) ?? NSNull()
|
||||||
lines.append("\(property.name): \(value)")
|
lines.append("\(property.name): \(value)")
|
||||||
}
|
}
|
||||||
organismType = organism.entity.managedObjectClassName
|
organismType = organism.entity.managedObjectClassName
|
||||||
}
|
}
|
||||||
|
|
||||||
self.titleLabel?.text = organismType
|
self.titleLabel?.text = organismType
|
||||||
self.organismLabel?.text = lines.joinWithSeparator("\n")
|
self.organismLabel?.text = lines.joined(separator: "\n")
|
||||||
self.progressView?.progress = 0
|
self.progressView?.progress = 0
|
||||||
|
|
||||||
self.headerContainer?.setNeedsLayout()
|
self.headerContainer?.setNeedsLayout()
|
||||||
@@ -311,11 +311,11 @@ class MigrationsDemoViewController: UIViewController {
|
|||||||
|
|
||||||
tableView.layoutIfNeeded()
|
tableView.layoutIfNeeded()
|
||||||
|
|
||||||
if let indexPath = self.lastSelectedIndexPath where indexPath.row < tableView.numberOfRowsInSection(0) {
|
if let indexPath = self.lastSelectedIndexPath where indexPath.row < tableView.numberOfRows(inSection: 0) {
|
||||||
|
|
||||||
tableView.selectRowAtIndexPath(indexPath,
|
tableView.selectRow(at: indexPath,
|
||||||
animated: scrollToSelection && animated,
|
animated: scrollToSelection && animated,
|
||||||
scrollPosition: scrollToSelection ? .Middle : .None
|
scrollPosition: scrollToSelection ? .middle : .none
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,14 +328,14 @@ extension MigrationsDemoViewController: ListObserver {
|
|||||||
|
|
||||||
// MARK: ListObserver
|
// MARK: ListObserver
|
||||||
|
|
||||||
func listMonitorWillChange(monitor: ListMonitor<NSManagedObject>) { }
|
func listMonitorWillChange(_ monitor: ListMonitor<NSManagedObject>) { }
|
||||||
|
|
||||||
func listMonitorDidChange(monitor: ListMonitor<NSManagedObject>) {
|
func listMonitorDidChange(_ monitor: ListMonitor<NSManagedObject>) {
|
||||||
|
|
||||||
if self.lastSelectedIndexPath == nil && self.listMonitor?.numberOfObjectsInSection(0) > 0 {
|
if self.lastSelectedIndexPath == nil && self.listMonitor?.numberOfObjectsInSection(0) > 0 {
|
||||||
|
|
||||||
self.tableView?.reloadData()
|
self.tableView?.reloadData()
|
||||||
self.setSelectedIndexPath(NSIndexPath(forRow: 0, inSection: 0), scrollToSelection: false)
|
self.setSelectedIndexPath(IndexPath(row: 0, section: 0), scrollToSelection: false)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@@ -351,14 +351,14 @@ extension MigrationsDemoViewController: UITableViewDataSource, UITableViewDelega
|
|||||||
|
|
||||||
// MARK: UITableViewDataSource
|
// MARK: UITableViewDataSource
|
||||||
|
|
||||||
@objc dynamic func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
@objc dynamic func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
||||||
return self.listMonitor?.numberOfObjectsInSection(0) ?? 0
|
return self.listMonitor?.numberOfObjectsInSection(0) ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc dynamic func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
@objc dynamic func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
||||||
let cell = tableView.dequeueReusableCellWithIdentifier("OrganismTableViewCell", forIndexPath: indexPath) as! OrganismTableViewCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: "OrganismTableViewCell", for: indexPath) as! OrganismTableViewCell
|
||||||
|
|
||||||
let dna = (self.listMonitor?[indexPath] as? OrganismProtocol)?.dna.description ?? ""
|
let dna = (self.listMonitor?[indexPath] as? OrganismProtocol)?.dna.description ?? ""
|
||||||
cell.dnaLabel?.text = "DNA: \(dna)"
|
cell.dnaLabel?.text = "DNA: \(dna)"
|
||||||
@@ -390,7 +390,7 @@ extension MigrationsDemoViewController: UITableViewDataSource, UITableViewDelega
|
|||||||
|
|
||||||
// MARK: UITableViewDelegate
|
// MARK: UITableViewDelegate
|
||||||
|
|
||||||
@objc dynamic func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
@objc dynamic func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
|
||||||
self.setSelectedIndexPath(indexPath, scrollToSelection: false)
|
self.setSelectedIndexPath(indexPath, scrollToSelection: false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import CoreData
|
|||||||
|
|
||||||
class OrganismV2ToV3MigrationPolicy: NSEntityMigrationPolicy {
|
class OrganismV2ToV3MigrationPolicy: NSEntityMigrationPolicy {
|
||||||
|
|
||||||
override func createDestinationInstancesForSourceInstance(sInstance: NSManagedObject, entityMapping mapping: NSEntityMapping, manager: NSMigrationManager) throws {
|
override func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws {
|
||||||
|
|
||||||
try super.createDestinationInstancesForSourceInstance(sInstance, entityMapping: mapping, manager: manager)
|
try super.createDestinationInstances(forSource: sInstance, in: mapping, manager: manager)
|
||||||
|
|
||||||
for dInstance in manager.destinationInstancesForEntityMappingNamed(mapping.name, sourceInstances: [sInstance]) {
|
for dInstance in manager.destinationInstances(forEntityMappingName: mapping.name, sourceInstances: [sInstance]) {
|
||||||
|
|
||||||
dInstance.setValue(false, forKey: "hasVertebrae")
|
dInstance.setValue(false, forKey: "hasVertebrae")
|
||||||
dInstance.setValue(sInstance.valueForKey("numberOfFlippers"), forKey: "numberOfLimbs")
|
dInstance.setValue(sInstance.value(forKey: "numberOfFlippers"), forKey: "numberOfLimbs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ private struct Static {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
dataStack.beginSynchronous { (transaction) -> Void in
|
_ = dataStack.beginSynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
transaction.deleteAll(From(UserAccount))
|
transaction.deleteAll(From<UserAccount>())
|
||||||
|
|
||||||
let account1 = transaction.create(Into<MaleAccount>(maleConfiguration))
|
let account1 = transaction.create(Into<MaleAccount>(maleConfiguration))
|
||||||
account1.accountType = "Facebook"
|
account1.accountType = "Facebook"
|
||||||
@@ -47,7 +47,7 @@ private struct Static {
|
|||||||
account2.name = "Jane Doe HCD"
|
account2.name = "Jane Doe HCD"
|
||||||
account2.friends = 314
|
account2.friends = 314
|
||||||
|
|
||||||
transaction.commitAndWait()
|
_ = transaction.commitAndWait()
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataStack
|
return dataStack
|
||||||
@@ -71,9 +71,9 @@ private struct Static {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
dataStack.beginSynchronous { (transaction) -> Void in
|
_ = dataStack.beginSynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
transaction.deleteAll(From(UserAccount))
|
transaction.deleteAll(From<UserAccount>())
|
||||||
|
|
||||||
let account1 = transaction.create(Into<MaleAccount>(maleConfiguration))
|
let account1 = transaction.create(Into<MaleAccount>(maleConfiguration))
|
||||||
account1.accountType = "Twitter"
|
account1.accountType = "Twitter"
|
||||||
@@ -85,7 +85,7 @@ private struct Static {
|
|||||||
account2.name = "#janedoe_hcd"
|
account2.name = "#janedoe_hcd"
|
||||||
account2.friends = 100
|
account2.friends = 100
|
||||||
|
|
||||||
transaction.commitAndWait()
|
_ = transaction.commitAndWait()
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataStack
|
return dataStack
|
||||||
@@ -107,46 +107,46 @@ class StackSetupDemoViewController: UITableViewController {
|
|||||||
|
|
||||||
// MARK: UIViewController
|
// MARK: UIViewController
|
||||||
|
|
||||||
override func viewWillAppear(animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
self.tableView.reloadData()
|
self.tableView.reloadData()
|
||||||
|
|
||||||
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
|
let indexPath = IndexPath(row: 0, section: 0)
|
||||||
self.tableView.selectRowAtIndexPath(indexPath, animated: false, scrollPosition: .None)
|
self.tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
|
||||||
self.updateDetailsWithAccount(self.accounts[indexPath.section][indexPath.row])
|
self.updateDetails(account: self.accounts[indexPath.section][indexPath.row])
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
let alert = UIAlertController(
|
let alert = UIAlertController(
|
||||||
title: "Setup Demo",
|
title: "Setup Demo",
|
||||||
message: "This demo shows how to initialize 2 DataStacks with 2 configurations each, for a total of 4 SQLite files, each with 1 instance of a \"UserAccount\" entity.",
|
message: "This demo shows how to initialize 2 DataStacks with 2 configurations each, for a total of 4 SQLite files, each with 1 instance of a \"UserAccount\" entity.",
|
||||||
preferredStyle: .Alert
|
preferredStyle: .alert
|
||||||
)
|
)
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
|
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
|
||||||
self.presentViewController(alert, animated: true, completion: nil)
|
self.present(alert, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: UITableViewDataSource
|
// MARK: UITableViewDataSource
|
||||||
|
|
||||||
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
|
||||||
return self.accounts.count
|
return self.accounts.count
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
||||||
return self.accounts[section].count
|
return self.accounts[section].count
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
||||||
let cell = tableView.dequeueReusableCellWithIdentifier("UITableViewCell")!
|
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell")!
|
||||||
|
|
||||||
let account = self.accounts[indexPath.section][indexPath.row]
|
let account = self.accounts[indexPath.section][indexPath.row]
|
||||||
cell.textLabel?.text = account.name
|
cell.textLabel?.text = account.name
|
||||||
@@ -158,13 +158,13 @@ class StackSetupDemoViewController: UITableViewController {
|
|||||||
|
|
||||||
// MARK: UITableViewDelegate
|
// MARK: UITableViewDelegate
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
|
||||||
let account = self.accounts[indexPath.section][indexPath.row]
|
let account = self.accounts[indexPath.section][indexPath.row]
|
||||||
self.updateDetailsWithAccount(account)
|
self.updateDetails(account: account)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||||
|
|
||||||
switch section {
|
switch section {
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ class StackSetupDemoViewController: UITableViewController {
|
|||||||
@IBOutlet private dynamic weak var nameLabel: UILabel?
|
@IBOutlet private dynamic weak var nameLabel: UILabel?
|
||||||
@IBOutlet private dynamic weak var friendsLabel: UILabel?
|
@IBOutlet private dynamic weak var friendsLabel: UILabel?
|
||||||
|
|
||||||
private func updateDetailsWithAccount(account: UserAccount) {
|
private func updateDetails(account: UserAccount) {
|
||||||
|
|
||||||
self.accountTypeLabel?.text = account.accountType
|
self.accountTypeLabel?.text = account.accountType
|
||||||
self.nameLabel?.text = account.name
|
self.nameLabel?.text = account.name
|
||||||
|
|||||||
@@ -26,17 +26,17 @@ private struct Static {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
var place = CoreStore.fetchOne(From(Place))
|
var place = CoreStore.fetchOne(From<Place>())
|
||||||
if place == nil {
|
if place == nil {
|
||||||
|
|
||||||
CoreStore.beginSynchronous { (transaction) -> Void in
|
_ = CoreStore.beginSynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
let place = transaction.create(Into(Place))
|
let place = transaction.create(Into<Place>())
|
||||||
place.setInitialValues()
|
place.setInitialValues()
|
||||||
|
|
||||||
transaction.commitAndWait()
|
_ = transaction.commitAndWait()
|
||||||
}
|
}
|
||||||
place = CoreStore.fetchOne(From(Place))
|
place = CoreStore.fetchOne(From<Place>())
|
||||||
}
|
}
|
||||||
|
|
||||||
return CoreStore.monitorObject(place!)
|
return CoreStore.monitorObject(place!)
|
||||||
@@ -71,33 +71,33 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec
|
|||||||
Static.placeController.addObserver(self)
|
Static.placeController.addObserver(self)
|
||||||
|
|
||||||
self.navigationItem.rightBarButtonItem = UIBarButtonItem(
|
self.navigationItem.rightBarButtonItem = UIBarButtonItem(
|
||||||
barButtonSystemItem: .Refresh,
|
barButtonSystemItem: .refresh,
|
||||||
target: self,
|
target: self,
|
||||||
action: #selector(self.refreshButtonTapped(_:))
|
action: #selector(self.refreshButtonTapped(_:))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
let alert = UIAlertController(
|
let alert = UIAlertController(
|
||||||
title: "Transactions Demo",
|
title: "Transactions Demo",
|
||||||
message: "This demo shows how to use the 3 types of transactions to save updates: synchronous, asynchronous, and unsafe.\n\nTap and hold on the map to change the pin location.",
|
message: "This demo shows how to use the 3 types of transactions to save updates: synchronous, asynchronous, and unsafe.\n\nTap and hold on the map to change the pin location.",
|
||||||
preferredStyle: .Alert
|
preferredStyle: .alert
|
||||||
)
|
)
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
|
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
|
||||||
self.presentViewController(alert, animated: true, completion: nil)
|
self.present(alert, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
if let mapView = self.mapView, let place = Static.placeController.object {
|
if let mapView = self.mapView, let place = Static.placeController.object {
|
||||||
|
|
||||||
mapView.addAnnotation(place)
|
mapView.addAnnotation(place)
|
||||||
mapView.setCenterCoordinate(place.coordinate, animated: false)
|
mapView.setCenter(place.coordinate, animated: false)
|
||||||
mapView.selectAnnotation(place, animated: false)
|
mapView.selectAnnotation(place, animated: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,11 +108,11 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec
|
|||||||
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
|
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
|
||||||
|
|
||||||
let identifier = "MKAnnotationView"
|
let identifier = "MKAnnotationView"
|
||||||
var annotationView: MKPinAnnotationView! = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as? MKPinAnnotationView
|
var annotationView: MKPinAnnotationView! = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKPinAnnotationView
|
||||||
if annotationView == nil {
|
if annotationView == nil {
|
||||||
|
|
||||||
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
|
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
|
||||||
annotationView.enabled = true
|
annotationView.isEnabled = true
|
||||||
annotationView.canShowCallout = true
|
annotationView.canShowCallout = true
|
||||||
annotationView.animatesDrop = true
|
annotationView.animatesDrop = true
|
||||||
}
|
}
|
||||||
@@ -127,28 +127,28 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec
|
|||||||
|
|
||||||
// MARK: ObjectObserver
|
// MARK: ObjectObserver
|
||||||
|
|
||||||
func objectMonitor(monitor: ObjectMonitor<Place>, willUpdateObject object: Place) {
|
func objectMonitor(_ monitor: ObjectMonitor<Place>, willUpdateObject object: Place) {
|
||||||
|
|
||||||
// none
|
// none
|
||||||
}
|
}
|
||||||
|
|
||||||
func objectMonitor(monitor: ObjectMonitor<Place>, didUpdateObject object: Place, changedPersistentKeys: Set<KeyPath>) {
|
func objectMonitor(_ monitor: ObjectMonitor<Place>, didUpdateObject object: Place, changedPersistentKeys: Set<KeyPath>) {
|
||||||
|
|
||||||
if let mapView = self.mapView {
|
if let mapView = self.mapView {
|
||||||
|
|
||||||
mapView.removeAnnotations(mapView.annotations ?? [])
|
mapView.removeAnnotations(mapView.annotations ?? [])
|
||||||
mapView.addAnnotation(object)
|
mapView.addAnnotation(object)
|
||||||
mapView.setCenterCoordinate(object.coordinate, animated: true)
|
mapView.setCenter(object.coordinate, animated: true)
|
||||||
mapView.selectAnnotation(object, animated: true)
|
mapView.selectAnnotation(object, animated: true)
|
||||||
|
|
||||||
if changedPersistentKeys.contains("latitude") || changedPersistentKeys.contains("longitude") {
|
if changedPersistentKeys.contains("latitude") || changedPersistentKeys.contains("longitude") {
|
||||||
|
|
||||||
self.geocodePlace(object)
|
self.geocode(place: object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func objectMonitor(monitor: ObjectMonitor<Place>, didDeleteObject object: Place) {
|
func objectMonitor(_ monitor: ObjectMonitor<Place>, didDeleteObject object: Place) {
|
||||||
|
|
||||||
// none
|
// none
|
||||||
}
|
}
|
||||||
@@ -160,13 +160,13 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec
|
|||||||
|
|
||||||
@IBOutlet weak var mapView: MKMapView?
|
@IBOutlet weak var mapView: MKMapView?
|
||||||
|
|
||||||
@IBAction dynamic func longPressGestureRecognized(sender: AnyObject?) {
|
@IBAction dynamic func longPressGestureRecognized(_ sender: AnyObject?) {
|
||||||
|
|
||||||
if let mapView = self.mapView, let gesture = sender as? UILongPressGestureRecognizer where gesture.state == .Began {
|
if let mapView = self.mapView, let gesture = sender as? UILongPressGestureRecognizer where gesture.state == .began {
|
||||||
|
|
||||||
let coordinate = mapView.convertPoint(
|
let coordinate = mapView.convert(
|
||||||
gesture.locationInView(mapView),
|
gesture.location(in: mapView),
|
||||||
toCoordinateFromView: mapView
|
toCoordinateFrom: mapView
|
||||||
)
|
)
|
||||||
CoreStore.beginAsynchronous { (transaction) -> Void in
|
CoreStore.beginAsynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
@@ -177,17 +177,17 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction dynamic func refreshButtonTapped(sender: AnyObject?) {
|
@IBAction dynamic func refreshButtonTapped(_ sender: AnyObject?) {
|
||||||
|
|
||||||
CoreStore.beginSynchronous { (transaction) -> Void in
|
_ = CoreStore.beginSynchronous { (transaction) -> Void in
|
||||||
|
|
||||||
let place = transaction.edit(Static.placeController.object)
|
let place = transaction.edit(Static.placeController.object)
|
||||||
place?.setInitialValues()
|
place?.setInitialValues()
|
||||||
transaction.commitAndWait()
|
_ = transaction.commitAndWait()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func geocodePlace(place: Place) {
|
func geocode(place: Place) {
|
||||||
|
|
||||||
let transaction = CoreStore.beginUnsafe()
|
let transaction = CoreStore.beginUnsafe()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user