WIP: docs

This commit is contained in:
John Estropia
2019-10-19 09:34:31 +09:00
parent 0b18366ab1
commit 326b897b06
10 changed files with 354 additions and 125 deletions

View File

@@ -67,7 +67,7 @@ final class CollectionViewDemoViewController: UICollectionViewController {
case UICollectionView.elementKindSectionHeader:
let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "PaletteCollectionSectionHeaderView", for: indexPath) as! PaletteCollectionSectionHeaderView
view.label?.text = ColorsDemo.palettes.sectionIdentifiers[indexPath.section]
view.label?.text = ColorsDemo.palettes.snapshot.sectionIDs[indexPath.section]
return view
default:
@@ -110,7 +110,7 @@ final class CollectionViewDemoViewController: UICollectionViewController {
self.performSegue(
withIdentifier: "ObjectObserverDemoViewController",
sender: ColorsDemo.palettes[indexPath: indexPath]
sender: ColorsDemo.palettes.snapshot[indexPath]
)
}

View File

@@ -45,9 +45,11 @@ struct ColorsDemo {
didSet {
self.palettes.refetch(
self.filter.whereClause(),
OrderBy<Palette>(.ascending(\.hue))
try! self.palettes.refetch(
From<Palette>()
.sectionBy(\.colorName)
.where(self.filter.whereClause())
.orderBy(.ascending(\.hue))
)
}
}

View File

@@ -23,7 +23,7 @@ final class ListObserverDemoViewController: UITableViewController {
switch editingStyle {
case .delete:
let palette = ColorsDemo.palettes[indexPath: indexPath]
let palette = ColorsDemo.palettes.snapshot[indexPath]
ColorsDemo.stack.perform(
asynchronous: { (transaction) in
@@ -122,7 +122,7 @@ final class ListObserverDemoViewController: UITableViewController {
self.performSegue(
withIdentifier: "ObjectObserverDemoViewController",
sender: ColorsDemo.palettes[indexPath: indexPath]
sender: ColorsDemo.palettes.snapshot[indexPath]
)
}

View File

@@ -23,20 +23,23 @@ struct SwiftUIView: View {
var body: some View {
NavigationView {
List {
ForEach(palettes.sectionIdentifiers, id: \.self) { (sectionID) in
ForEach(palettes.snapshot.sectionIDs, id: \.self) { (sectionID) in
Section(header: Text(sectionID)) {
ForEach(self.palettes[section: sectionID], id: \.self) { palette in
ForEach(self.palettes.snapshot.items(inSectionWithID: sectionID), id: \.self) { palette in
NavigationLink(
destination: DetailView(palette: palette),
label: { ColorCell(palette: palette) }
)
}
.onDelete { itemIndices in
let objectsToDelete = self.palettes[section: sectionID, itemIndices: itemIndices]
let objectIDsToDelete = self.palettes.snapshot.itemIDs(
inSectionWithID: sectionID,
atIndices: itemIndices
)
self.dataStack.perform(
asynchronous: { transaction in
transaction.delete(objectsToDelete)
transaction.delete(objectIDs: objectIDsToDelete)
},
completion: { _ in }
)
@@ -44,7 +47,7 @@ struct SwiftUIView: View {
}
}
}
.navigationBarTitle(Text("SwiftUI (\(palettes.numberOfItems) objects)"))
.navigationBarTitle(Text("SwiftUI (\(palettes.snapshot.numberOfItems) objects)"))
.navigationBarItems(
leading: EditButton(),
trailing: HStack {