Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13819882
UserDefaults+Extensions.swift
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
UserDefaults+Extensions.swift
View Options
import
Foundation
enum
WFDefaults
{
static
let
isLoggedIn
=
"isLoggedIn"
static
let
showAllPostsFlag
=
"showAllPostsFlag"
static
let
selectedCollectionURL
=
"selectedCollectionURL"
static
let
lastDraftURL
=
"lastDraftURL"
static
let
colorSchemeIntegerKey
=
"colorSchemeIntegerKey"
static
let
defaultFontIntegerKey
=
"defaultFontIntegerKey"
static
let
usernameStringKey
=
"usernameStringKey"
static
let
serverStringKey
=
"serverStringKey"
#if
os
(
macOS
)
static
let
automaticallyChecksForUpdates
=
"automaticallyChecksForUpdates"
static
let
subscribeToBetaUpdates
=
"subscribeToBetaUpdates"
#endif
static
let
didHaveFatalError
=
"didHaveFatalError"
static
let
fatalErrorDescription
=
"fatalErrorDescription"
}
extension
UserDefaults
{
private
static
let
appGroupName
:
String
=
"group.com.abunchtell.writefreely"
private
static
let
didMigrateDefaultsToAppGroup
:
String
=
"didMigrateDefaultsToAppGroup"
private
static
let
didRemoveStandardDefaults
:
String
=
"didRemoveStandardDefaults"
static
var
shared
:
UserDefaults
{
if
let
groupDefaults
=
UserDefaults
(
suiteName
:
UserDefaults
.
appGroupName
),
groupDefaults
.
bool
(
forKey
:
UserDefaults
.
didMigrateDefaultsToAppGroup
)
{
return
groupDefaults
}
else
{
do
{
let
groupDefaults
=
try
UserDefaults
.
standard
.
migrateDefaultsToAppGroup
()
return
groupDefaults
}
catch
{
return
UserDefaults
.
standard
}
}
}
private
func
migrateDefaultsToAppGroup
()
throws
->
UserDefaults
{
let
userDefaults
=
UserDefaults
.
standard
let
groupDefaults
=
UserDefaults
(
suiteName
:
UserDefaults
.
appGroupName
)
if
let
groupDefaults
=
groupDefaults
{
if
groupDefaults
.
bool
(
forKey
:
UserDefaults
.
didMigrateDefaultsToAppGroup
)
{
return
groupDefaults
}
for
(
key
,
value
)
in
userDefaults
.
dictionaryRepresentation
()
{
groupDefaults
.
set
(
value
,
forKey
:
key
)
}
groupDefaults
.
set
(
true
,
forKey
:
UserDefaults
.
didMigrateDefaultsToAppGroup
)
return
groupDefaults
}
else
{
throw
UserDefaultsError
.
couldNotMigrateStandardDefaults
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Feb 16, 6:22 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3629292
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment