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 Mirror { | |
/// Use this to help you implement a custom debugDescription listing all properties of your instances | |
/// | |
/// - Parameters: | |
/// - subject: The instance for which to return the description. | |
/// | |
/// Example usage: | |
/// | |
/// extension MyType: CustomDebugStringConvertible { |
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 | |
//: Swift type-safe protocol versions of (Mutable)Copying | |
protocol SwiftCopying { | |
associatedtype NonMutableType = Self | |
func clone() -> NonMutableType | |
} | |
extension SwiftCopying where Self: NSCopying { | |
func clone() -> NonMutableType { | |
return self.copy() as! NonMutableType |
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/env ruby | |
require 'json' | |
require 'yaml' | |
require 'open-uri' | |
# [Array<String>] List of iOS/macOS apps | |
app_dirs = ['WordPress-iOS', 'woocommerce-ios', 'simplenote-ios', 'simplenote-macos', 'autoproxxy'] | |
specs_cache = File.join(__dir__, 'pod_stats.cache') |
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 | |
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 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
// Allow to use generics even if not supported yet | |
#if __has_feature(objc_generics) | |
#define NSArrayOf(x) NSArray<x> | |
#define NSMutableArrayOf(x) NSMutableArray<x> | |
#define NSDictionaryOf(x,y) NSDictionary<x, y> | |
#define NSMutableDictionaryOf(x, y) NSMutableDictionary<x, y> | |
#define NSSetOf(x) NSSet<x> | |
#define NSMutableSetOf(x) NSMutableSet<x> | |
#else | |
#define NSArrayOf(x) NSArray |
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
// Simple wrapper around NSRegularExpression to provide a swiftier API and, ability to have matches exposing Range instead of NSRange | |
import Foundation | |
struct RegEx { | |
let regex: NSRegularExpression | |
init(pattern: String, options: NSRegularExpression.Options = []) throws { | |
self.regex = try NSRegularExpression(pattern: pattern, options: options) | |
} |
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
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 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 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 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) |