mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Rename 'persistentContainer' to 'container'
This commit is contained in:
parent
11ad3bc2ff
commit
2f1b895df5
@ -58,7 +58,7 @@ struct AccountLogoutView: View {
|
|||||||
let request = WFAPost.createFetchRequest()
|
let request = WFAPost.createFetchRequest()
|
||||||
request.predicate = NSPredicate(format: "status == %i", 1)
|
request.predicate = NSPredicate(format: "status == %i", 1)
|
||||||
do {
|
do {
|
||||||
let editedPosts = try LocalStorageManager.standard.persistentContainer.viewContext.fetch(request)
|
let editedPosts = try LocalStorageManager.standard.container.viewContext.fetch(request)
|
||||||
if editedPosts.count == 1 {
|
if editedPosts.count == 1 {
|
||||||
editedPostsWarningString = "You'll lose unpublished changes to \(editedPosts.count) edited post. "
|
editedPostsWarningString = "You'll lose unpublished changes to \(editedPosts.count) edited post. "
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ extension WriteFreelyModel {
|
|||||||
let fetchedCollections = try result.get()
|
let fetchedCollections = try result.get()
|
||||||
for fetchedCollection in fetchedCollections {
|
for fetchedCollection in fetchedCollections {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
let localCollection = WFACollection(context: LocalStorageManager.standard.persistentContainer.viewContext)
|
let localCollection = WFACollection(context: LocalStorageManager.standard.container.viewContext)
|
||||||
localCollection.alias = fetchedCollection.alias
|
localCollection.alias = fetchedCollection.alias
|
||||||
localCollection.blogDescription = fetchedCollection.description
|
localCollection.blogDescription = fetchedCollection.description
|
||||||
localCollection.email = fetchedCollection.email
|
localCollection.email = fetchedCollection.email
|
||||||
@ -130,7 +130,7 @@ extension WriteFreelyModel {
|
|||||||
}
|
}
|
||||||
let request = WFAPost.createFetchRequest()
|
let request = WFAPost.createFetchRequest()
|
||||||
do {
|
do {
|
||||||
let locallyCachedPosts = try LocalStorageManager.standard.persistentContainer.viewContext.fetch(request)
|
let locallyCachedPosts = try LocalStorageManager.standard.container.viewContext.fetch(request)
|
||||||
do {
|
do {
|
||||||
var postsToDelete = locallyCachedPosts.filter { $0.status != PostStatus.local.rawValue }
|
var postsToDelete = locallyCachedPosts.filter { $0.status != PostStatus.local.rawValue }
|
||||||
let fetchedPosts = try result.get()
|
let fetchedPosts = try result.get()
|
||||||
@ -146,7 +146,7 @@ extension WriteFreelyModel {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
let managedPost = WFAPost(context: LocalStorageManager.standard.persistentContainer.viewContext)
|
let managedPost = WFAPost(context: LocalStorageManager.standard.container.viewContext)
|
||||||
managedPost.postId = fetchedPost.postId
|
managedPost.postId = fetchedPost.postId
|
||||||
managedPost.slug = fetchedPost.slug
|
managedPost.slug = fetchedPost.slug
|
||||||
managedPost.appearance = fetchedPost.appearance
|
managedPost.appearance = fetchedPost.appearance
|
||||||
@ -222,7 +222,7 @@ extension WriteFreelyModel {
|
|||||||
request.predicate = matchBodyPredicate
|
request.predicate = matchBodyPredicate
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let cachedPostsResults = try LocalStorageManager.standard.persistentContainer.viewContext.fetch(request)
|
let cachedPostsResults = try LocalStorageManager.standard.container.viewContext.fetch(request)
|
||||||
guard let cachedPost = cachedPostsResults.first else { return }
|
guard let cachedPost = cachedPostsResults.first else { return }
|
||||||
cachedPost.appearance = fetchedPost.appearance
|
cachedPost.appearance = fetchedPost.appearance
|
||||||
cachedPost.body = fetchedPost.body
|
cachedPost.body = fetchedPost.body
|
||||||
@ -293,7 +293,7 @@ extension WriteFreelyModel {
|
|||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
LocalStorageManager.standard.persistentContainer.viewContext.rollback()
|
LocalStorageManager.standard.container.viewContext.rollback()
|
||||||
}
|
}
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,17 @@ import AppKit
|
|||||||
|
|
||||||
final class LocalStorageManager {
|
final class LocalStorageManager {
|
||||||
public static var standard = LocalStorageManager()
|
public static var standard = LocalStorageManager()
|
||||||
public let persistentContainer: NSPersistentContainer
|
public let container: NSPersistentContainer
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
// Set up the persistent container.
|
// Set up the persistent container.
|
||||||
persistentContainer = NSPersistentContainer(name: "LocalStorageModel")
|
container = NSPersistentContainer(name: "LocalStorageModel")
|
||||||
persistentContainer.loadPersistentStores { description, error in
|
container.loadPersistentStores { description, error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
fatalError("Core Data store failed to load with error: \(error)")
|
fatalError("Core Data store failed to load with error: \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
persistentContainer.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
|
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
|
||||||
|
|
||||||
let center = NotificationCenter.default
|
let center = NotificationCenter.default
|
||||||
|
|
||||||
@ -37,9 +37,9 @@ final class LocalStorageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveContext() {
|
func saveContext() {
|
||||||
if persistentContainer.viewContext.hasChanges {
|
if container.viewContext.hasChanges {
|
||||||
do {
|
do {
|
||||||
try persistentContainer.viewContext.save()
|
try container.viewContext.save()
|
||||||
} catch {
|
} catch {
|
||||||
print("Error saving context: \(error)")
|
print("Error saving context: \(error)")
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ final class LocalStorageManager {
|
|||||||
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try persistentContainer.viewContext.executeAndMergeChanges(using: deleteRequest)
|
try container.viewContext.executeAndMergeChanges(using: deleteRequest)
|
||||||
} catch {
|
} catch {
|
||||||
print("Error: Failed to purge cached collections.")
|
print("Error: Failed to purge cached collections.")
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ struct ContentView: View {
|
|||||||
|
|
||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let model = WriteFreelyModel()
|
let model = WriteFreelyModel()
|
||||||
|
|
||||||
return ContentView()
|
return ContentView()
|
||||||
|
@ -2,7 +2,7 @@ import SwiftUI
|
|||||||
|
|
||||||
struct CollectionListView: View {
|
struct CollectionListView: View {
|
||||||
@EnvironmentObject var model: WriteFreelyModel
|
@EnvironmentObject var model: WriteFreelyModel
|
||||||
@ObservedObject var collections = CollectionListModel(managedObjectContext: LocalStorageManager.standard.persistentContainer.viewContext)
|
@ObservedObject var collections = CollectionListModel(managedObjectContext: LocalStorageManager.standard.container.viewContext)
|
||||||
@State var selectedCollection: WFACollection?
|
@State var selectedCollection: WFACollection?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@ -43,7 +43,7 @@ struct CollectionListView: View {
|
|||||||
|
|
||||||
struct CollectionListView_LoggedOutPreviews: PreviewProvider {
|
struct CollectionListView_LoggedOutPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let model = WriteFreelyModel()
|
let model = WriteFreelyModel()
|
||||||
|
|
||||||
return CollectionListView()
|
return CollectionListView()
|
||||||
|
@ -27,7 +27,7 @@ struct PostEditorModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateNewLocalPost(withFont appearance: Int) -> WFAPost {
|
func generateNewLocalPost(withFont appearance: Int) -> WFAPost {
|
||||||
let managedPost = WFAPost(context: LocalStorageManager.standard.persistentContainer.viewContext)
|
let managedPost = WFAPost(context: LocalStorageManager.standard.container.viewContext)
|
||||||
managedPost.createdDate = Date()
|
managedPost.createdDate = Date()
|
||||||
managedPost.title = ""
|
managedPost.title = ""
|
||||||
managedPost.body = ""
|
managedPost.body = ""
|
||||||
@ -55,9 +55,9 @@ struct PostEditorModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func fetchManagedObject(from objectURL: URL) -> NSManagedObject? {
|
private func fetchManagedObject(from objectURL: URL) -> NSManagedObject? {
|
||||||
let coordinator = LocalStorageManager.standard.persistentContainer.persistentStoreCoordinator
|
let coordinator = LocalStorageManager.standard.container.persistentStoreCoordinator
|
||||||
guard let managedObjectID = coordinator.managedObjectID(forURIRepresentation: objectURL) else { return nil }
|
guard let managedObjectID = coordinator.managedObjectID(forURIRepresentation: objectURL) else { return nil }
|
||||||
let object = LocalStorageManager.standard.persistentContainer.viewContext.object(with: managedObjectID)
|
let object = LocalStorageManager.standard.container.viewContext.object(with: managedObjectID)
|
||||||
return object
|
return object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ struct PostEditorStatusToolbarView: View {
|
|||||||
|
|
||||||
struct PESTView_StandardPreviews: PreviewProvider {
|
struct PESTView_StandardPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let model = WriteFreelyModel()
|
let model = WriteFreelyModel()
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.status = PostStatus.published.rawValue
|
testPost.status = PostStatus.published.rawValue
|
||||||
@ -77,7 +77,7 @@ struct PESTView_StandardPreviews: PreviewProvider {
|
|||||||
|
|
||||||
struct PESTView_OutdatedLocalCopyPreviews: PreviewProvider {
|
struct PESTView_OutdatedLocalCopyPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let model = WriteFreelyModel()
|
let model = WriteFreelyModel()
|
||||||
let updatedPost = WFAPost(context: context)
|
let updatedPost = WFAPost(context: context)
|
||||||
updatedPost.status = PostStatus.published.rawValue
|
updatedPost.status = PostStatus.published.rawValue
|
||||||
@ -90,7 +90,7 @@ struct PESTView_OutdatedLocalCopyPreviews: PreviewProvider {
|
|||||||
|
|
||||||
struct PESTView_DeletedRemoteCopyPreviews: PreviewProvider {
|
struct PESTView_DeletedRemoteCopyPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let model = WriteFreelyModel()
|
let model = WriteFreelyModel()
|
||||||
let deletedPost = WFAPost(context: context)
|
let deletedPost = WFAPost(context: context)
|
||||||
deletedPost.status = PostStatus.published.rawValue
|
deletedPost.status = PostStatus.published.rawValue
|
||||||
|
@ -46,7 +46,7 @@ struct PostCellView: View {
|
|||||||
|
|
||||||
struct PostCell_AllPostsPreviews: PreviewProvider {
|
struct PostCell_AllPostsPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.title = "Test Post Title"
|
testPost.title = "Test Post Title"
|
||||||
testPost.body = "Here's some cool sample body text."
|
testPost.body = "Here's some cool sample body text."
|
||||||
@ -59,7 +59,7 @@ struct PostCell_AllPostsPreviews: PreviewProvider {
|
|||||||
|
|
||||||
struct PostCell_NormalPreviews: PreviewProvider {
|
struct PostCell_NormalPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.title = "Test Post Title"
|
testPost.title = "Test Post Title"
|
||||||
testPost.body = "Here's some cool sample body text."
|
testPost.body = "Here's some cool sample body text."
|
||||||
@ -73,7 +73,7 @@ struct PostCell_NormalPreviews: PreviewProvider {
|
|||||||
|
|
||||||
struct PostCell_NoTitlePreviews: PreviewProvider {
|
struct PostCell_NoTitlePreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.title = ""
|
testPost.title = ""
|
||||||
testPost.body = "Here's some cool sample body text."
|
testPost.body = "Here's some cool sample body text."
|
||||||
|
@ -4,7 +4,7 @@ import CoreData
|
|||||||
class PostListModel: ObservableObject {
|
class PostListModel: ObservableObject {
|
||||||
func remove(_ post: WFAPost) {
|
func remove(_ post: WFAPost) {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
LocalStorageManager.standard.persistentContainer.viewContext.delete(post)
|
LocalStorageManager.standard.container.viewContext.delete(post)
|
||||||
LocalStorageManager.standard.saveContext()
|
LocalStorageManager.standard.saveContext()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -15,7 +15,7 @@ class PostListModel: ObservableObject {
|
|||||||
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try LocalStorageManager.standard.persistentContainer.viewContext.executeAndMergeChanges(using: deleteRequest)
|
try LocalStorageManager.standard.container.viewContext.executeAndMergeChanges(using: deleteRequest)
|
||||||
} catch {
|
} catch {
|
||||||
print("Error: Failed to purge cached posts.")
|
print("Error: Failed to purge cached posts.")
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ struct PostListView: View {
|
|||||||
|
|
||||||
struct PostListView_Previews: PreviewProvider {
|
struct PostListView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let model = WriteFreelyModel()
|
let model = WriteFreelyModel()
|
||||||
|
|
||||||
return PostListView(showAllPosts: true)
|
return PostListView(showAllPosts: true)
|
||||||
|
@ -38,7 +38,7 @@ struct PostStatusBadgeView: View {
|
|||||||
|
|
||||||
struct PostStatusBadge_LocalDraftPreviews: PreviewProvider {
|
struct PostStatusBadge_LocalDraftPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.status = PostStatus.local.rawValue
|
testPost.status = PostStatus.local.rawValue
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ struct PostStatusBadge_LocalDraftPreviews: PreviewProvider {
|
|||||||
|
|
||||||
struct PostStatusBadge_EditedPreviews: PreviewProvider {
|
struct PostStatusBadge_EditedPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.status = PostStatus.edited.rawValue
|
testPost.status = PostStatus.edited.rawValue
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ struct PostStatusBadge_EditedPreviews: PreviewProvider {
|
|||||||
|
|
||||||
struct PostStatusBadge_PublishedPreviews: PreviewProvider {
|
struct PostStatusBadge_PublishedPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.status = PostStatus.published.rawValue
|
testPost.status = PostStatus.published.rawValue
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ struct WriteFreely_MultiPlatformApp: App {
|
|||||||
// }
|
// }
|
||||||
})
|
})
|
||||||
.environmentObject(model)
|
.environmentObject(model)
|
||||||
.environment(\.managedObjectContext, LocalStorageManager.standard.persistentContainer.viewContext)
|
.environment(\.managedObjectContext, LocalStorageManager.standard.container.viewContext)
|
||||||
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
||||||
}
|
}
|
||||||
.commands {
|
.commands {
|
||||||
|
@ -236,7 +236,7 @@ struct PostEditorView: View {
|
|||||||
|
|
||||||
struct PostEditorView_EmptyPostPreviews: PreviewProvider {
|
struct PostEditorView_EmptyPostPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.createdDate = Date()
|
testPost.createdDate = Date()
|
||||||
testPost.appearance = "norm"
|
testPost.appearance = "norm"
|
||||||
@ -251,7 +251,7 @@ struct PostEditorView_EmptyPostPreviews: PreviewProvider {
|
|||||||
|
|
||||||
struct PostEditorView_ExistingPostPreviews: PreviewProvider {
|
struct PostEditorView_ExistingPostPreviews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let context = LocalStorageManager.standard.persistentContainer.viewContext
|
let context = LocalStorageManager.standard.container.viewContext
|
||||||
let testPost = WFAPost(context: context)
|
let testPost = WFAPost(context: context)
|
||||||
testPost.title = "Test Post Title"
|
testPost.title = "Test Post Title"
|
||||||
testPost.body = "Here's some cool sample body text."
|
testPost.body = "Here's some cool sample body text."
|
||||||
|
Loading…
Reference in New Issue
Block a user