Skip to content

Commit 9172c9f

Browse files
authored
Storage API v2 (#15)
Internally, storage now goes through a `NoteStorage` protocol instance. This is the abstraction layer that will let me experiment with a sqlite file format.
1 parent 7cce54d commit 9172c9f

29 files changed

Lines changed: 788 additions & 657 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Uncomitted
4+
5+
### Changed
6+
7+
- Internally, storage now goes through a `NoteStorage` protocol instance. This is the abstraction layer that will let me experiment with a sqlite file format.
8+
39
## [0.13.0] - 2019-09-28
410

511
### Changed

CommonplaceBookApp.xcodeproj/project.pbxproj

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
637F8B0C22AE186100698868 /* MiniMarkdown in Frameworks */ = {isa = PBXBuildFile; productRef = 637F8B0B22AE186100698868 /* MiniMarkdown */; };
1212
BE050A647575E8F075868DF1 /* Pods_CommonplaceBookApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A8D2C034B73F8605B9C553FE /* Pods_CommonplaceBookApp.framework */; };
1313
D30B0243229E513C00F3B459 /* StudyLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = D30B0242229E513C00F3B459 /* StudyLog.swift */; };
14-
D30B0245229EB88900F3B459 /* NoteArchiveDocument+TextEditViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D30B0244229EB88900F3B459 /* NoteArchiveDocument+TextEditViewController.swift */; };
14+
D30B0245229EB88900F3B459 /* SavingTextEditViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D30B0244229EB88900F3B459 /* SavingTextEditViewController.swift */; };
1515
D30BD4F822A0B13B007E1F31 /* ParsingRules+CommonplaceBook.swift in Sources */ = {isa = PBXBuildFile; fileRef = D30BD4F722A0B13B007E1F31 /* ParsingRules+CommonplaceBook.swift */; };
1616
D30BD4FC22A0B8C2007E1F31 /* Optional+Collection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D30BD4FB22A0B8C2007E1F31 /* Optional+Collection.swift */; };
1717
D30D261823193F9A0031AA20 /* VocabularyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D30D261723193F9A0031AA20 /* VocabularyViewController.swift */; };
@@ -73,8 +73,10 @@
7373
D375D33C20ED9BEC00EAB4F0 /* DocumentListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D375D33B20ED9BEC00EAB4F0 /* DocumentListViewController.swift */; };
7474
D375D33E20EDA08F00EAB4F0 /* DocumentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D375D33D20EDA08F00EAB4F0 /* DocumentTableViewCell.swift */; };
7575
D37E6D34228D7AC6006CD0FA /* Observable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D37E6D33228D7AC6006CD0FA /* Observable.swift */; };
76-
D37E6D36228D9DD8006CD0FA /* PageProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = D37E6D35228D9DD8006CD0FA /* PageProperties.swift */; };
76+
D37E6D36228D9DD8006CD0FA /* NoteProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = D37E6D35228D9DD8006CD0FA /* NoteProperties.swift */; };
7777
D37E6D38228DBC88006CD0FA /* CommonCrypto+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = D37E6D37228DBC88006CD0FA /* CommonCrypto+Swift.swift */; };
78+
D38862B423BB94FA00A44F1C /* Note.swift in Sources */ = {isa = PBXBuildFile; fileRef = D38862B323BB94FA00A44F1C /* Note.swift */; };
79+
D38862B623BE404300A44F1C /* Note+Markdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = D38862B523BE404300A44F1C /* Note+Markdown.swift */; };
7880
D39015C2229025EA0097B182 /* NoteArchiveDocumentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39015C1229025EA0097B182 /* NoteArchiveDocumentTests.swift */; };
7981
D3A6EFAD20EE500D00AC428D /* FileMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A6EFAC20EE500D00AC428D /* FileMetadata.swift */; };
8082
D3A99ED422EDDCA7000D6DE2 /* DocumentTableController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A99ED322EDDCA7000D6DE2 /* DocumentTableController.swift */; };
@@ -86,8 +88,8 @@
8688
D3C5C7DE232E871F00A8BEDF /* QuestionAndAnswerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3C5C7DD232E871F00A8BEDF /* QuestionAndAnswerTests.swift */; };
8789
D3C5C7E0232E891200A8BEDF /* QuestionAndAnswer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3C5C7DF232E891200A8BEDF /* QuestionAndAnswer.swift */; };
8890
D3C5D26A214B1A7A0055F6B5 /* KeyboardInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3C5D269214B1A7A0055F6B5 /* KeyboardInfo.swift */; };
89-
D3D3688E229C579200E4D062 /* NoteArchiveDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D3688D229C579200E4D062 /* NoteArchiveDocument.swift */; };
90-
D3D36890229C61F500E4D062 /* NoteArchiveDocument+Importing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D3688F229C61F500E4D062 /* NoteArchiveDocument+Importing.swift */; };
91+
D3CC03CA23BA734C003393DC /* NoteStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3CC03C923BA734C003393DC /* NoteStorage.swift */; };
92+
D3D3688E229C579200E4D062 /* NoteDocumentStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D3688D229C579200E4D062 /* NoteDocumentStorage.swift */; };
9193
D3D36892229C9A8000E4D062 /* Date+CloseEnough.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D36891229C9A8000E4D062 /* Date+CloseEnough.swift */; };
9294
D3D50A2D231AC8EB007440F1 /* VocabularyChallengeTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D50A2C231AC8EB007440F1 /* VocabularyChallengeTemplate.swift */; };
9395
D3DC5EC320EC9B0100F0B74B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3DC5EC220EC9B0100F0B74B /* AppDelegate.swift */; };
@@ -145,7 +147,7 @@
145147
C2519F393D974710775AF26A /* Pods_CommonplaceBookAppTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CommonplaceBookAppTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
146148
C69D2589A8BFE5C01679833D /* Pods-CommonplaceBookApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CommonplaceBookApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-CommonplaceBookApp/Pods-CommonplaceBookApp.release.xcconfig"; sourceTree = "<group>"; };
147149
D30B0242229E513C00F3B459 /* StudyLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudyLog.swift; sourceTree = "<group>"; };
148-
D30B0244229EB88900F3B459 /* NoteArchiveDocument+TextEditViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NoteArchiveDocument+TextEditViewController.swift"; sourceTree = "<group>"; };
150+
D30B0244229EB88900F3B459 /* SavingTextEditViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SavingTextEditViewController.swift; sourceTree = "<group>"; };
149151
D30BD4F722A0B13B007E1F31 /* ParsingRules+CommonplaceBook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ParsingRules+CommonplaceBook.swift"; sourceTree = "<group>"; };
150152
D30BD4FB22A0B8C2007E1F31 /* Optional+Collection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Optional+Collection.swift"; sourceTree = "<group>"; };
151153
D30D261723193F9A0031AA20 /* VocabularyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VocabularyViewController.swift; sourceTree = "<group>"; };
@@ -210,8 +212,10 @@
210212
D375D33D20EDA08F00EAB4F0 /* DocumentTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentTableViewCell.swift; sourceTree = "<group>"; };
211213
D375D33F20EDCE1700EAB4F0 /* CommonplaceBookApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CommonplaceBookApp.entitlements; sourceTree = "<group>"; };
212214
D37E6D33228D7AC6006CD0FA /* Observable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Observable.swift; sourceTree = "<group>"; };
213-
D37E6D35228D9DD8006CD0FA /* PageProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageProperties.swift; sourceTree = "<group>"; };
215+
D37E6D35228D9DD8006CD0FA /* NoteProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteProperties.swift; sourceTree = "<group>"; };
214216
D37E6D37228DBC88006CD0FA /* CommonCrypto+Swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CommonCrypto+Swift.swift"; sourceTree = "<group>"; };
217+
D38862B323BB94FA00A44F1C /* Note.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Note.swift; sourceTree = "<group>"; };
218+
D38862B523BE404300A44F1C /* Note+Markdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Note+Markdown.swift"; sourceTree = "<group>"; };
215219
D39015C1229025EA0097B182 /* NoteArchiveDocumentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteArchiveDocumentTests.swift; sourceTree = "<group>"; };
216220
D3A6EFAC20EE500D00AC428D /* FileMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileMetadata.swift; sourceTree = "<group>"; };
217221
D3A99ED322EDDCA7000D6DE2 /* DocumentTableController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentTableController.swift; sourceTree = "<group>"; };
@@ -223,8 +227,8 @@
223227
D3C5C7DD232E871F00A8BEDF /* QuestionAndAnswerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionAndAnswerTests.swift; sourceTree = "<group>"; };
224228
D3C5C7DF232E891200A8BEDF /* QuestionAndAnswer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionAndAnswer.swift; sourceTree = "<group>"; };
225229
D3C5D269214B1A7A0055F6B5 /* KeyboardInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardInfo.swift; sourceTree = "<group>"; };
226-
D3D3688D229C579200E4D062 /* NoteArchiveDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteArchiveDocument.swift; sourceTree = "<group>"; };
227-
D3D3688F229C61F500E4D062 /* NoteArchiveDocument+Importing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NoteArchiveDocument+Importing.swift"; sourceTree = "<group>"; };
230+
D3CC03C923BA734C003393DC /* NoteStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteStorage.swift; sourceTree = "<group>"; };
231+
D3D3688D229C579200E4D062 /* NoteDocumentStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteDocumentStorage.swift; sourceTree = "<group>"; };
228232
D3D36891229C9A8000E4D062 /* Date+CloseEnough.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+CloseEnough.swift"; sourceTree = "<group>"; };
229233
D3D50A2C231AC8EB007440F1 /* VocabularyChallengeTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VocabularyChallengeTemplate.swift; sourceTree = "<group>"; };
230234
D3DC5EBF20EC9B0100F0B74B /* CommonplaceBookApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CommonplaceBookApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -370,25 +374,28 @@
370374
D3DC5ED020EC9B0200F0B74B /* Info.plist */,
371375
D3C5D269214B1A7A0055F6B5 /* KeyboardInfo.swift */,
372376
D3DC5ECD20EC9B0200F0B74B /* LaunchScreen.storyboard */,
377+
D36214652334F607008C8FF4 /* LayoutManager.swift */,
373378
D31AFA89229D61E900ED2B76 /* LoadingViewController.swift */,
374379
D3591501231C340100883AC4 /* LocaleAwareTextField.swift */,
375380
D3FD46A52329257C008FDAE4 /* LoggingSpeechSynthesizer.swift */,
376381
D54C311D21E7E3CD007AE62E /* MarkdownEditingTextView.swift */,
377382
D31AFA9B229D61EC00ED2B76 /* MetadataQuery.swift */,
383+
D38862B323BB94FA00A44F1C /* Note.swift */,
384+
D38862B523BE404300A44F1C /* Note+Markdown.swift */,
378385
D33F64742298C70C008C3A92 /* NoteArchive.swift */,
379-
D3D3688D229C579200E4D062 /* NoteArchiveDocument.swift */,
380-
D3D3688F229C61F500E4D062 /* NoteArchiveDocument+Importing.swift */,
381-
D30B0244229EB88900F3B459 /* NoteArchiveDocument+TextEditViewController.swift */,
386+
D3D3688D229C579200E4D062 /* NoteDocumentStorage.swift */,
387+
D37E6D35228D9DD8006CD0FA /* NoteProperties.swift */,
388+
D3CC03C923BA734C003393DC /* NoteStorage.swift */,
382389
D31AFA9F229D61EC00ED2B76 /* NSAttributedString+ChapterAndVerse.swift */,
383390
D37E6D33228D7AC6006CD0FA /* Observable.swift */,
384391
D30BD4FB22A0B8C2007E1F31 /* Optional+Collection.swift */,
385-
D37E6D35228D9DD8006CD0FA /* PageProperties.swift */,
386392
D30BD4F722A0B13B007E1F31 /* ParsingRules+CommonplaceBook.swift */,
387393
D31AFAAA229D61EE00ED2B76 /* PersonalitySpeechSynthesizer.swift */,
388394
D3C5C7DF232E891200A8BEDF /* QuestionAndAnswer.swift */,
389395
D3B3323F232FC55C00F0B710 /* QuestionAndAnswerTemplate.swift */,
390396
D339C6FD21EB928700924178 /* QuoteTemplate.swift */,
391397
D31AFA8D229D61E900ED2B76 /* RenderedMarkdown+Stylesheet.swift */,
398+
D30B0244229EB88900F3B459 /* SavingTextEditViewController.swift */,
392399
D3B8514D22AC0794004F3B95 /* Settings.bundle */,
393400
D33F647822999138008C3A92 /* String+ParsingHelpers.swift */,
394401
D31AFA8F229D61EB00ED2B76 /* String+Typography.swift */,
@@ -411,7 +418,6 @@
411418
D3591503231C3AC800883AC4 /* View+Locale.swift */,
412419
D3D50A2C231AC8EB007440F1 /* VocabularyChallengeTemplate.swift */,
413420
D30D261723193F9A0031AA20 /* VocabularyViewController.swift */,
414-
D36214652334F607008C8FF4 /* LayoutManager.swift */,
415421
);
416422
path = CommonplaceBookApp;
417423
sourceTree = "<group>";
@@ -667,9 +673,10 @@
667673
buildActionMask = 2147483647;
668674
files = (
669675
D33F64752298C70C008C3A92 /* NoteArchive.swift in Sources */,
670-
D30B0245229EB88900F3B459 /* NoteArchiveDocument+TextEditViewController.swift in Sources */,
676+
D30B0245229EB88900F3B459 /* SavingTextEditViewController.swift in Sources */,
671677
D374AB6B229655BA00F54561 /* TextSnippetArchive.swift in Sources */,
672678
D3DC5EE520EC9F7500F0B74B /* TextEditViewController.swift in Sources */,
679+
D38862B623BE404300A44F1C /* Note+Markdown.swift in Sources */,
673680
D31AFACB229D61EE00ED2B76 /* ChallengeTemplate.swift in Sources */,
674681
D3E98EFE21D2F784008445DA /* DirectoryMetadataProvider.swift in Sources */,
675682
D3D36892229C9A8000E4D062 /* Date+CloseEnough.swift in Sources */,
@@ -692,6 +699,7 @@
692699
D31AFAB6229D61EE00ED2B76 /* CardDocumentProperties.swift in Sources */,
693700
D37E6D38228DBC88006CD0FA /* CommonCrypto+Swift.swift in Sources */,
694701
D31AFAB9229D61EE00ED2B76 /* ClosedRange+SwiftFlash.swift in Sources */,
702+
D3CC03CA23BA734C003393DC /* NoteStorage.swift in Sources */,
695703
D31AFACA229D61EE00ED2B76 /* ClozeCard.swift in Sources */,
696704
D3C5D26A214B1A7A0055F6B5 /* KeyboardInfo.swift in Sources */,
697705
D33F646F22981E38008C3A92 /* TextSnippet.swift in Sources */,
@@ -715,8 +723,9 @@
715723
D33F64772298CE8E008C3A92 /* TextSnippetArchive+ChallengeTemplate.swift in Sources */,
716724
D54C311E21E7E3CD007AE62E /* MarkdownEditingTextView.swift in Sources */,
717725
D31AFAAD229D61EE00ED2B76 /* UIStackView+SetArrangedSubviews.swift in Sources */,
718-
D3D3688E229C579200E4D062 /* NoteArchiveDocument.swift in Sources */,
719-
D37E6D36228D9DD8006CD0FA /* PageProperties.swift in Sources */,
726+
D38862B423BB94FA00A44F1C /* Note.swift in Sources */,
727+
D3D3688E229C579200E4D062 /* NoteDocumentStorage.swift in Sources */,
728+
D37E6D36228D9DD8006CD0FA /* NoteProperties.swift in Sources */,
720729
D35E90C7230C5AD300A46B3F /* UserDefault.swift in Sources */,
721730
D3331C8722F4EF11002B62AF /* StringProtocol+FuzzyMatch.swift in Sources */,
722731
D3A99ED422EDDCA7000D6DE2 /* DocumentTableController.swift in Sources */,
@@ -737,7 +746,6 @@
737746
D3A6EFAD20EE500D00AC428D /* FileMetadata.swift in Sources */,
738747
D35E90C9230C755D00A46B3F /* UIApplication+Environment.swift in Sources */,
739748
D31AFAD6229D61EE00ED2B76 /* AnswerStatistics.swift in Sources */,
740-
D3D36890229C61F500E4D062 /* NoteArchiveDocument+Importing.swift in Sources */,
741749
D31AFAC5229D61EE00ED2B76 /* IdentifierToStudyMetadata.swift in Sources */,
742750
D30B0243229E513C00F3B459 /* StudyLog.swift in Sources */,
743751
);

CommonplaceBookApp/AppDelegate.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
3030
return loadingViewController
3131
}()
3232

33-
var noteArchiveDocument: NoteArchiveDocument?
33+
var noteArchiveDocument: NoteStorage?
3434
/// If non-nil, we want to open this page initially upon opening the document.
35-
var initialPageIdentifier: String?
35+
var initialPageIdentifier: Note.Identifier?
3636

3737
@UserDefault("opened_document", defaultValue: nil) var openedDocumentBookmark: Data?
3838
@UserDefault("has_run_0", defaultValue: false) var hasRun: Bool
@@ -103,7 +103,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
103103
break
104104
}
105105
DDLogInfo("Opening page \(uniqueIdentifier)")
106-
initialPageIdentifier = uniqueIdentifier
106+
initialPageIdentifier = Note.Identifier(rawValue: uniqueIdentifier)
107107
default:
108108
break
109109
}
@@ -202,7 +202,7 @@ extension AppDelegate: UIDocumentBrowserViewControllerDelegate {
202202
/// - parameter controller: The view controller from which to present the DocumentListViewController
203203
private func openDocument(at url: URL, from controller: UIDocumentBrowserViewController, animated: Bool) {
204204
DDLogInfo("Opening document at \(url)")
205-
let noteArchiveDocument = NoteArchiveDocument(
205+
let noteArchiveDocument = NoteDocumentStorage(
206206
fileURL: url,
207207
parsingRules: ParsingRules.commonplace
208208
)
@@ -224,9 +224,9 @@ extension AppDelegate: UIDocumentBrowserViewControllerDelegate {
224224
wrappedViewController.modalPresentationStyle = .fullScreen
225225
wrappedViewController.modalTransitionStyle = .crossDissolve
226226
controller.present(wrappedViewController, animated: animated, completion: nil)
227-
let pageIdentifierCopy = initialPageIdentifier
227+
let noteIdentifierCopy = initialPageIdentifier
228228
noteArchiveDocument.open(completionHandler: { success in
229-
pageIdentifierCopy.flatMap { documentListViewController.showPage(with: $0) }
229+
noteIdentifierCopy.flatMap { documentListViewController.showPage(with: $0) }
230230
let properties: [String: String] = [
231231
"Success": success.description,
232232
"documentState": String(describing: noteArchiveDocument.documentState),
@@ -249,7 +249,7 @@ extension AppDelegate: UIDocumentBrowserViewControllerDelegate {
249249
func documentBrowser(_ controller: UIDocumentBrowserViewController, didRequestDocumentCreationWithHandler importHandler: @escaping (URL?, UIDocumentBrowserViewController.ImportMode) -> Void) {
250250
let directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!
251251
let url = directoryURL.appendingPathComponent(UUID().uuidString).appendingPathExtension("notebundle")
252-
let document = NoteArchiveDocument(fileURL: url, parsingRules: ParsingRules.commonplace)
252+
let document = NoteDocumentStorage(fileURL: url, parsingRules: ParsingRules.commonplace)
253253
document.save(to: url, for: .forCreating) { saveSuccess in
254254
guard saveSuccess else {
255255
DDLogError("Could not save document to \(url): \(document.previousError?.localizedDescription ?? "nil")")
@@ -287,7 +287,7 @@ extension AppDelegate: UISplitViewControllerDelegate {
287287
) -> Bool {
288288
guard
289289
let navigationController = secondaryViewController as? UINavigationController,
290-
let textEditViewController = navigationController.visibleViewController as? TextEditViewController
290+
let textEditViewController = navigationController.visibleViewController as? SavingTextEditViewController
291291
else {
292292
assertionFailure()
293293
return false
@@ -299,7 +299,7 @@ extension AppDelegate: UISplitViewControllerDelegate {
299299
//
300300
// In our case, if the textEditViewController doesn't represent a real page, we don't
301301
// want to show it.
302-
return textEditViewController.pageIdentifier == nil
302+
return textEditViewController.noteIdentifier == nil
303303
}
304304
}
305305

CommonplaceBookApp/Array+Node.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ extension Array where Element == Node {
1414
].joined())
1515
}
1616

17+
func makeChallengeTemplates() -> [ChallengeTemplate] {
18+
var results: [ChallengeTemplate] = []
19+
results.append(contentsOf: ClozeTemplate.extract(from: self))
20+
results.append(contentsOf: QuoteTemplate.extract(from: self))
21+
results.append(contentsOf: QuestionAndAnswerTemplate.extract(from: self))
22+
return results
23+
}
24+
1725
/// Extracts the title from an array of nodes.
1826
///
1927
/// - note: If there is a heading anywhere in the nodes, the contents of the first heading

0 commit comments

Comments
 (0)