-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright © 2015 Abhishek Banthia | ||
|
||
import Foundation | ||
import CoreModelKit | ||
|
||
struct ConfigExport { | ||
|
||
private func generateJSONFromDefaults() { | ||
let selectedKeys: Set<String> = Set([ | ||
CLShowOnboardingFlow, | ||
CLSelectedTimeZoneFormatKey, | ||
CLThemeKey, | ||
CLShowDayInMenu, | ||
CLShowDateInMenu, | ||
CLShowPlaceInMenu, | ||
CLDisplayFutureSliderKey, | ||
CLStartAtLogin, | ||
CLShowAppInForeground, | ||
CLSunriseSunsetTime, | ||
CLUserFontSizePreference, | ||
CLShowUpcomingEventView, | ||
CLShowAllDayEventsInUpcomingView, | ||
CLShowMeetingInMenubar, | ||
CLTruncateTextLength, | ||
CLFutureSliderRange, | ||
CLSelectedCalendars, | ||
CLAppDisplayOptions, | ||
CLLongStatusBarWarningMessage, | ||
CLMenubarCompactMode, | ||
CLDefaultMenubarMode, | ||
CLInstallHomeIndicatorObject, | ||
CLSwitchToCompactModeAlert, | ||
CLDisplayDSTTransitionInfo | ||
]) | ||
let dictionaryRep = UserDefaults.standard.dictionaryRepresentation() | ||
var clockerPrefs: [String:Any] = [:] | ||
for (key, value) in dictionaryRep { | ||
if selectedKeys.contains(key) { | ||
print("Key is \(key) and value is \(value)") | ||
clockerPrefs[key] = value | ||
} | ||
} | ||
|
||
do { | ||
let decodeJSON: [[String: Any]] = DataStore.shared().timezones().compactMap { data -> [String: Any]? in | ||
guard let customObject = TimezoneData.customObject(from: data) else { return nil } | ||
let timezoneDictionary: [String: Any] = [ | ||
"Name": customObject.formattedAddress ?? "", | ||
"Custom": customObject.customLabel ?? "", | ||
"TimezoneID": customObject.timezoneID ?? "N/A", | ||
"Is System": customObject.isSystemTimezone ? 1 : 0, | ||
"Is Favorite": customObject.isFavourite == 1 ? 1 : 0, | ||
"Sunrise or Sunset": customObject.isSunriseOrSunset ? 1 : 0, | ||
"Latitude": customObject.latitude ?? 0.0, | ||
"Longitude": customObject.longitude ?? 0.0, | ||
"Place Identifier": customObject.placeID ?? "0.0", | ||
"Selection Type": "\(customObject.selectionType)", | ||
] | ||
return timezoneDictionary | ||
} | ||
|
||
let timezoneDict = ["Timezones": decodeJSON] | ||
clockerPrefs.merge(timezoneDict) { (current, _) in current} | ||
|
||
guard let documentDirectoryUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return } | ||
let fileUrl = documentDirectoryUrl.appendingPathComponent("Persons.json") | ||
// Transform array into data and save it into file | ||
do { | ||
let data = try JSONSerialization.data(withJSONObject: clockerPrefs, options: []) | ||
try data.write(to: fileUrl, options: []) | ||
} catch { | ||
print(error) | ||
} | ||
|
||
let json = try JSONSerialization.data(withJSONObject: clockerPrefs, options: .prettyPrinted) | ||
print(json) | ||
} catch { | ||
print("Failure Observed \(error.localizedDescription)") | ||
} | ||
|
||
} | ||
|
||
} |