Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ApolloZhu committed Sep 18, 2019
1 parent e1109db commit 3cf3d12
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
3 changes: 0 additions & 3 deletions CocoaPods/CocoaPods-macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {



func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}
Expand All @@ -21,6 +19,5 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Insert code here to tear down your application
}


}

4 changes: 2 additions & 2 deletions CocoaPods/CocoaPods-macOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import EFStorage
import KeychainAccess

extension Bool: KeychainAccessStorable {
public func asKeychainStorable() -> KeychainAccessStorable! {
return "\(self)"
public func asKeychainAccessStorable() -> Result<AsIsKeychainAccessStorable, Error> {
return "\(self)".asKeychainAccessStorable()
}
public static func fromKeychain(_ keychain: Keychain, forKey key: String) -> Bool? {
return String.fromKeychain(keychain, forKey: key).map {
Expand Down
13 changes: 9 additions & 4 deletions CocoaPods/Cocoapods/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ extension UserDefaults {
extension UIImage: YYCacheStorable { } // Auto synthesized implmentation for NSCoding

extension Double: KeychainAccessStorable {
public func asKeychainStorable() -> Result<AsIsKeychainAccessStorable, Error> {
return "\(self)".asKeychainStorable()
public func asKeychainAccessStorable() -> Result<AsIsKeychainAccessStorable, Error> {
return "\(self)".asKeychainAccessStorable()
}
public static func fromKeychain(_ keychain: Keychain, forKey key: String) -> Double? {
return String.fromKeychain(keychain, forKey: key).flatMap(Double.init)
Expand All @@ -47,9 +47,14 @@ extension EFStorageKeychainAccessRef {

// MARK: Allow optional default value

extension Optional: AsIsUserDefaultsStorable where Wrapped: AsIsUserDefaultsStorable { }

extension Optional: UserDefaultsStorable where Wrapped: UserDefaultsStorable {
public func asUserDefaultsStorable() -> AsIsUserDefaultsStorable! {
return self.flatMap { $0.asUserDefaultsStorable() }
public func asUserDefaultsStorable() -> Result<AsIsUserDefaultsStorable, Error> {
return map { $0.asUserDefaultsStorable() }
?? .success(nil as Optional<Int>)
// ^
// It can be any type `Optional<T> where T: AsIsUserDefaultsStorable`
}

public static func fromUserDefaults(_ userDefaults: UserDefaults, forKey key: String) -> Optional<Wrapped>? {
Expand Down
4 changes: 2 additions & 2 deletions Tests/EFStorageTests/EFStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import XCTest
import KeychainAccess

extension Bool: KeychainAccessStorable {
public func asKeychainStorable() -> Result<AsIsKeychainAccessStorable, Error> {
return "\(self)".asKeychainStorable()
public func asKeychainAccessStorable() -> Result<AsIsKeychainAccessStorable, Error> {
return "\(self)".asKeychainAccessStorable()
}
public static func fromKeychain(_ keychain: Keychain, forKey key: String) -> Bool? {
guard let string = try? keychain.getString(key) else { return nil }
Expand Down

0 comments on commit 3cf3d12

Please sign in to comment.