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
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
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
@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
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
#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
@propertyWrapper struct BundleFile<DataType> { | |
let name: String | |
let type: String | |
let fileManager: FileManager = .default | |
let bundle: Bundle = .main | |
let decoder: (Data) -> DataType | |
var wrappedValue: DataType { | |
guard let path = bundle.path(forResource: name, ofType: type) else { fatalError("Resource not found") } | |
guard let data = fileManager.contents(atPath: path) else { fatalError("File not loaded") } |
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
@IBDesignable | |
class MaskableView: <#AnyUIViewSubclass#> { | |
var maskImageView = UIImageView() | |
@IBInspectable | |
var maskImage: UIImage? { | |
didSet { | |
maskImageView.image = maskImage | |
updateView() | |
} |
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 | |
struct Fallible<Value: Decodable>: Decodable { | |
var wrappedValue: [Value] = [] | |
private struct _None: Decodable {} | |
init(from decoder: Decoder) throws { | |
var container = try decoder.unkeyedContainer() | |
while !container.isAtEnd { | |
if let decoded = try? container.decode(Value.self) { |