デバイスの正当な所有者であることを
- 生体認証のみで認証する
- 生体認証またはiOSパスワードで認証する
- 生体認証またはアプリ独自の認証方式で認証する
を選べる。
| extension Array where Element == URLQueryItem { | |
| func stringValue(for name: String) -> String? { | |
| let item = first { $0.name == name } | |
| return item?.value | |
| } | |
| func urlValue(for name: String) -> URL? { | |
| guard let string = stringValue(for: name) else { return nil } | |
| return URL(string: string) |
| import Foundation | |
| // MARK: - URLQueryItem Key | |
| class URLQueryItemKeys { | |
| init() {} | |
| } | |
| class URLQueryItemKey<Value : URLQueryItemValueCompatible> : URLQueryItemKeys { | |
| let name: String |
| import Foundation | |
| // URLQueryKey | |
| public class URLQueryKeys { | |
| public init() {} | |
| } | |
| public class URLQueryKey : URLQueryKeys, ExpressibleByStringLiteral { | |
| var name: String |
| import UIKit | |
| // UserDefaults | |
| extension UserDefaults { | |
| public func value<Value : UserDefaultCompatible>(type: Value.Type = Value.self, forKey key: String, default defaultValue: Value) -> Value { | |
| guard let object = object(forKey: key) else { return defaultValue } | |
| return Value(userDefaultObject: object) ?? defaultValue | |
| } | |
| public func setValue<Value : UserDefaultCompatible>(_ value: Value, forKey key: String) { |
| import Combine | |
| do { | |
| let subject: CurrentValueSubject<Int, Error> = .init(1) | |
| subject.send(completion: .finished) | |
| // completionしているとsinkで即competionが呼ばれる | |
| let cancelable = subject.sink(receiveCompletion: { (completion) in | |
| completion | |
| return |
| import Combine | |
| class MySubject<Output, Failure : Error> : Combine.Subject { | |
| var value: Output { | |
| didSet { | |
| // 値が変更されたらsubscriptionに通知します。 | |
| // Subject -> Subscription -> Subscriber の順に値が送られます。 | |
| subscriptions.forEach { $0.receive(value) } | |
| } | |
| } |
| import Combine | |
| class MySubject<Output, Failure : Error> : Combine.Subject { | |
| var value: Output { | |
| didSet { | |
| // 完了していなければ値を通知する | |
| guard completion == nil else { return } | |
| subscriptions.forEach { $0.receive(value) } | |
| } | |
| } |
| import UIKit | |
| import Combine | |
| // これだけでは使いにくい。 | |
| // * 色々な型への対応 | |
| // * Property WrapperのprojectedValueとしてCurrentValueSubjectを返す | |
| // とすれば使いやすくなるはず。 | |
| class Box { | |
| var cancelable: AnyCancellable? |
| import UIKit | |
| import Combine | |
| // MARK: - UserDefaults | |
| public protocol UserDefaultsProtocol: NSObject { | |
| func value<Value: UserDefaultCompatible>(type: Value.Type, forKey key: String, default defaultValue: Value) -> Value | |
| func setValue<Value: UserDefaultCompatible>(_ value: Value, forKey key: String) | |
| } |