Created
January 21, 2018 08:06
-
-
Save mczachurski/5bcb3120e679ba59dd2e41a9cdf83a45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import CoreData | |
| import UIKit | |
| class SettingsHandler : CoreDataHandler { | |
| func getDefaultSettings() -> Settings { | |
| var settingsList:[Settings] = [] | |
| let context = self.getManagedObjectContext() | |
| let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Settings") | |
| do { | |
| settingsList = try context.fetch(fetchRequest) as! [Settings] | |
| } | |
| catch { | |
| print("Error during fetching favourites") | |
| } | |
| var settings:Settings? = nil | |
| if settingsList.count == 0 { | |
| settings = self.createSettingsEntity() | |
| self.save() | |
| } | |
| else { | |
| settings = settingsList.first | |
| } | |
| return settings! | |
| } | |
| func save(settings: Settings) { | |
| self.save() | |
| } | |
| private func createSettingsEntity() -> Settings | |
| { | |
| let context = self.getManagedObjectContext() | |
| return Settings(context: context) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment