This file contains hidden or 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
#if os(macOS) | |
public typealias ViewRepresentable = NSViewRepresentable | |
public typealias NativeView = NSView | |
#elseif os(iOS) | |
public typealias ViewRepresentable = UIViewRepresentable | |
public typealias NativeView = UIView | |
#endif | |
public protocol ViewRepresentableHelper: ViewRepresentable { | |
associatedtype ViewType: NativeView |
This file contains hidden or 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
import Foundation | |
@propertyWrapper | |
public struct UserDefaultStorage<T: Codable> { | |
private let key: String | |
private let defaultValue: T | |
private let userDefaults: UserDefaults | |
public init(key: String, default: T, store: UserDefaults = .standard) { |
This file contains hidden or 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
@propertyWrapper | |
public struct SettingsBundleStorage<T> { | |
private let key: String | |
private let userDefaults: UserDefaults = .standard | |
public init(key: String) { | |
self.key = key | |
setBundleDefaults(plist: .root) |
This file contains hidden or 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
infix operator .. | |
@inline(__always) | |
func ..<T: EmptyInitializable>(lhs: T, rhs: (T)->()) -> T { | |
rhs(lhs) | |
return lhs | |
} | |
/* Example: |
This file contains hidden or 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
extension UIResponder { | |
func nextFirstResponder(where condition: (UIResponder) -> Bool ) -> UIResponder? { | |
guard let next = next else { return nil } | |
if condition(next) { return next } | |
else { return next.nextFirstResponder(where: condition) } | |
} | |
} |
This file contains hidden or 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
func validateNationalCode(_ code: String) -> Bool { | |
let stringCode = code.trimmingCharacters(in: CharacterSet.decimalDigits.inverted) | |
if code.allSatisfy({ $0 == code.first }) { return false } | |
guard stringCode.count == 10 else { return false } | |
var convertedCode = code.compactMap { Int(String($0)) } | |
guard convertedCode.count == 10 else { return false } |
This file contains hidden or 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
switch identifier { | |
// MARK: - iPhone Identifiers | |
case "iPhone1,1": return "iPhone" | |
case "iPhone1,2": return "iPhone 3G" | |
case "iPhone2,1": return "iPhone 3GS" | |
case "iPhone3,1": return "iPhone 4" | |
case "iPhone3,2": return "iPhone 4 GSM Rev A" | |
case "iPhone3,3": return "iPhone 4 CDMA" | |
case "iPhone4,1": return "iPhone 4S" |
Since iOS 12, the system can read the one-time password from the received SMS automatically and add it above the keyboard, So users can use the code with only one touch. There are rules and limitations for doing this as I tried to list most of them below:
- The message must contain the Code prase. Some other words like passcode and password are ok too in English.
- The Code phrase (with or without
:
) must be separate with only one space with your numbers.
example:
Code 1111111
Code: 111111