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 using<T: AnyObject>(object: T, execute: (T) throws -> Void) rethrows -> T { | |
try execute(object) | |
return object | |
} | |
import UIKit | |
// Then in some configureView() function of an UIViewController or whatnot… | |
let label1 = using(UILabel()) { |
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 UIKit | |
class CopyLabel : UILabel { | |
// MARK: Setup | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
configureMenu() | |
} |
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
/*: | |
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI | |
The only purpose of this code is to implement those wrappers myself | |
just to understand how they work internally and why they are needed, | |
⚠️ This is not supposed to be a reference implementation nor cover all | |
subtleties of the real Binding and State types. | |
The only purpose of this playground is to show how re-implementing | |
them myself has helped me understand the whole thing better |
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
enum Demo { | |
case simple | |
case oneValue(Int) | |
case twoValues(String, Double) | |
case threeValues(one: Int, two: Float, [Int]) | |
} | |
//: # Direct exposition in the enum | |
//: ## Sourcery Template |
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
// Xcode 11b1 | |
@propertyDelegate | |
struct Clamped<Value: Comparable> { | |
private var storage: Value | |
private var clamp: (Value) -> Value | |
init(min: Value, max: Value, initialValue: Value) { | |
let clampingFunction = { ($0...$0).clamped(to: min...max).lowerBound } | |
self.storage = clampingFunction(initialValue) |
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 | |
protocol TransformerType { | |
associatedtype BaseType | |
associatedtype TypeForCoding: Codable | |
static var encodeTransform: (BaseType) throws -> TypeForCoding { get } | |
static var decodeTransform: (TypeForCoding) throws -> BaseType { get } | |
} | |
@propertyWrapper |
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
struct Contact: Decodable, CustomStringConvertible { | |
var id: String | |
@NestedKey | |
var firstname: String | |
@NestedKey | |
var lastname: String | |
@NestedKey | |
var address: String | |
enum CodingKeys: String, NestableCodingKey { |
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
// Create by love : Mohammad Nasrabadi [github](https://github.com/mmnasrabadi) | |
import UIKit | |
protocol CodablePro: Codable { | |
func toJsonString() -> String | |
typealias JSON = [String : Any] | |
func toDictionary() -> JSON? | |
init?(json: JSON) | |
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
Setting up the beautiful terminal by ZSH and Oh My ZSH installations | |
ohmyzsh github page: | |
https://github.com/ohmyzsh/ohmyzsh | |
Themes : | |
https://github.com/ohmyzsh/ohmyzsh/wiki/Themes |
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
echo "\033[31;32m \033[0m" | |
echo "\033[31;32m ## \033[0m" | |
echo "\033[31;32m ### \033[0m" | |
echo "\033[31;32m ###** #########*####**** \033[0m" | |
echo "\033[31;32m ## ############********* #* \033[0m" | |
echo "\033[31;32m *######***** ### #* \033[0m" | |
echo "\033[31;32m # * #* \033[0m" | |
echo "\033[31;32m ## # # ## ###' #* |