diff --git a/CocoaPods/CocoaPods-macOS/AppDelegate.swift b/CocoaPods/CocoaPods-macOS/AppDelegate.swift index d58030e..297ecd1 100644 --- a/CocoaPods/CocoaPods-macOS/AppDelegate.swift +++ b/CocoaPods/CocoaPods-macOS/AppDelegate.swift @@ -11,8 +11,6 @@ import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { - - func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application } @@ -21,6 +19,5 @@ class AppDelegate: NSObject, NSApplicationDelegate { // Insert code here to tear down your application } - } diff --git a/CocoaPods/CocoaPods-macOS/ViewController.swift b/CocoaPods/CocoaPods-macOS/ViewController.swift index da2daa6..2f7d727 100644 --- a/CocoaPods/CocoaPods-macOS/ViewController.swift +++ b/CocoaPods/CocoaPods-macOS/ViewController.swift @@ -11,8 +11,8 @@ import EFStorage import KeychainAccess extension Bool: KeychainAccessStorable { - public func asKeychainStorable() -> KeychainAccessStorable! { - return "\(self)" + public func asKeychainAccessStorable() -> Result { + return "\(self)".asKeychainAccessStorable() } public static func fromKeychain(_ keychain: Keychain, forKey key: String) -> Bool? { return String.fromKeychain(keychain, forKey: key).map { diff --git a/CocoaPods/Cocoapods/ViewController.swift b/CocoaPods/Cocoapods/ViewController.swift index 8c9a082..4216cb2 100644 --- a/CocoaPods/Cocoapods/ViewController.swift +++ b/CocoaPods/Cocoapods/ViewController.swift @@ -30,8 +30,8 @@ extension UserDefaults { extension UIImage: YYCacheStorable { } // Auto synthesized implmentation for NSCoding extension Double: KeychainAccessStorable { - public func asKeychainStorable() -> Result { - return "\(self)".asKeychainStorable() + public func asKeychainAccessStorable() -> Result { + return "\(self)".asKeychainAccessStorable() } public static func fromKeychain(_ keychain: Keychain, forKey key: String) -> Double? { return String.fromKeychain(keychain, forKey: key).flatMap(Double.init) @@ -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 { + return map { $0.asUserDefaultsStorable() } + ?? .success(nil as Optional) + // ^ + // It can be any type `Optional where T: AsIsUserDefaultsStorable` } public static func fromUserDefaults(_ userDefaults: UserDefaults, forKey key: String) -> Optional? { diff --git a/Tests/EFStorageTests/EFStorageTests.swift b/Tests/EFStorageTests/EFStorageTests.swift index 3e2bc9f..ada2c73 100644 --- a/Tests/EFStorageTests/EFStorageTests.swift +++ b/Tests/EFStorageTests/EFStorageTests.swift @@ -9,8 +9,8 @@ import XCTest import KeychainAccess extension Bool: KeychainAccessStorable { - public func asKeychainStorable() -> Result { - return "\(self)".asKeychainStorable() + public func asKeychainAccessStorable() -> Result { + return "\(self)".asKeychainAccessStorable() } public static func fromKeychain(_ keychain: Keychain, forKey key: String) -> Bool? { guard let string = try? keychain.getString(key) else { return nil }