[ABANDONED] Mastodon iOS client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

6 years ago
  1. //
  2. // CoreDataManager.swift
  3. // elpha-ios
  4. //
  5. // Created by Dwayne Harris on 9/28/18.
  6. // Copyright © 2018 Elpha. All rights reserved.
  7. //
  8. import CoreData
  9. import Foundation
  10. public class CoreDataManager {
  11. static let shared = CoreDataManager()
  12. lazy var persistentContainer: NSPersistentContainer = {
  13. let container = NSPersistentContainer(name: "Elpha")
  14. container.loadPersistentStores(completionHandler: { (storeDescription, error) in
  15. if let error = error as NSError? {
  16. fatalError("Unresolved error \(error), \(error.userInfo)")
  17. }
  18. })
  19. return container
  20. }()
  21. var context: NSManagedObjectContext {
  22. get {
  23. return persistentContainer.viewContext
  24. }
  25. }
  26. func saveContext() {
  27. if context.hasChanges {
  28. do {
  29. try context.save()
  30. } catch {
  31. let nserror = error as NSError
  32. fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
  33. }
  34. }
  35. }
  36. }