-
Notifications
You must be signed in to change notification settings - Fork 213
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
45 changed files
with
1,427 additions
and
1,092 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,48 @@ | ||
// | ||
// AppEnvStorage.swift | ||
// EhPanda | ||
// | ||
// Created by 荒木辰造 on R 3/07/10. | ||
// | ||
|
||
import SwiftyBeaver | ||
|
||
@propertyWrapper | ||
struct AppEnvStorage<T: Encodable> { | ||
private var key: String | ||
|
||
private var appEnv: AppEnv { | ||
PersistenceController.fetchAppEnvNonNil() | ||
} | ||
|
||
var wrappedValue: T { | ||
get { | ||
let mirror = Mirror(reflecting: appEnv) | ||
for child in mirror.children where child.label == key { | ||
if let value = child.value as? T { | ||
return value | ||
} | ||
} | ||
SwiftyBeaver.error( | ||
"Failed in force downcasting to generic type..." | ||
+ "Shutting down now..." | ||
) | ||
fatalError() | ||
} | ||
set { | ||
PersistenceController.update { appEnvMO in | ||
appEnvMO.setValue(newValue.toData(), forKeyPath: key) | ||
} | ||
} | ||
} | ||
|
||
init(type: T.Type, key: String? = nil) { | ||
if let key = key { | ||
self.key = key | ||
} else { | ||
self.key = String( | ||
describing: type | ||
).lowercased() | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.