This file contains 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
/* | |
* | |
* Generates a random and strong password in the format xxx-xxx-xxx-xxx. | |
* Note: Not available on WatchOS. | |
* | |
*/ | |
import Security |
This file contains 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
/* | |
* | |
* I recommend using RxSwift, Combine or PromiseKit for this kind of flow. | |
* | |
*/ | |
import UIKit | |
import Foundation | |
func wait<A,B>(_ blockA: @escaping (@escaping (Result<A,Error>) -> Void) -> Void, |
This file contains 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
# !/usr/bin/python3 | |
""" | |
Asset catalogs are not accessible in your Xcode project because they are compiled archive (.car files) so doing | |
something like Bundle.main.url().. won't work. | |
""" | |
""" | |
1. Manually add a file colors.json to your Xcode project on the level ${PROJECT_DIR}/project_name/<here> and |
This file contains 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 Combine | |
import Foundation | |
extension Future where Failure == Error { | |
convenience init(promise: @escaping (@escaping (Result<Output, Failure>) -> Void) throws -> Void) { | |
self.init({ (innerPromise) in | |
do { | |
try promise { innerPromise($0) } | |
} catch { | |
innerPromise(.failure(error)) |
This file contains 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
/* | |
* | |
* Use this when the publisher only publishes 1 value then stops. | |
* | |
*/ | |
import Combine | |
import Foundation |
This file contains 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 UIImage: Codable { | |
// works | |
public func encode(to encoder: Encoder) throws { | |
var container = encoder.singleValueContainer() | |
try container.encode(pngData()!) | |
} |
This file contains 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 UIKit | |
class ViewController: UIViewController { | |
private let textView = UITextView() | |
private var beforeNumberOfLines: Int? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
This file contains 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 ??? | |
func ???<T> (_ value: @autoclosure () -> T?, _ error: @autoclosure () -> Error) throws -> T { | |
guard let value = value() else { | |
throw error() | |
} | |
return value | |
} |
This file contains 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 | |
struct Defaults<Value> { | |
let key: Key | |
let defaultValue: Value | |
var wrappedValue: Value { |
This file contains 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 os.log | |
import Foundation | |
@propertyWrapper | |
struct Redactable<Value: Codable & Hashable>: Codable, Hashable, CustomLeafReflectable, | |
CustomStringConvertible, CustomDebugStringConvertible, CustomPlaygroundDisplayConvertible { | |
private let value: Value | |
var isRedactionEnabled = true |
OlderNewer