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
{ | |
"word": "foose ball" | |
} |
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
{ | |
"big": "b", | |
"big one": "b", | |
"small": "s", | |
"small one": "s", | |
"small garage": "s" | |
} |
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 Decodable { | |
// Converts a dictionary to the desired type | |
static func decode(dictionary: [String: Any]) throws -> Self { | |
let data = try JSONSerialization.data(withJSONObject: dictionary, options: []) | |
return (try JSONDecoder().decode(Self.self, from: data)) | |
} | |
} | |
extension Encodable { | |
// Turns your object into Data |
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
# Checkouts out all branches based on arg name. e.g. master | |
function git_checkout_all { CMD="git checkout $1 && git submodule foreach 'git checkout $1'"; eval $CMD; }; git_checkout_all master; | |
# Make branch for all e.g. feature | |
function git_branch_all { CMD="git branch $1 && git submodule foreach 'git branch $1'"; eval $CMD; }; git_branch_all feature; | |
# Commit all | |
function git_commit_all { CMD="git submodule foreach 'git commit -am \"$1\" || echo \"\"' && git commit -am \"$1\""; eval $CMD; }; git_commit_all "msg"; |
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
// This class helps facilitate using non-standard defaults. | |
// Typically standardDefaults will save into "<bundle_identifier>.plist" | |
// You can use a different one. The BundleUserDefaults class will save into "BundleUserDefaults.plist" | |
// This means you can clear it without effecting the standard one. | |
// Base class that all user defaults inherit from | |
class MyUserDefaults: NSObject { | |
public let suiteName: String | |
public let user_default: UserDefaults | |
init(suiteName: String) { |
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
for gr in view.gestureRecognizers ?? [] where gr is UITapGestureRecognizer | |
{ | |
let tgr = gr as! UITapGestureRecognizer | |
if let _targets = tgr.value(forKey: "targets") as? NSArray { | |
let targets = _targets as [AnyObject] | |
for targetAction in targets { | |
if let desc = targetAction.value(forKey: "description") as? String | |
, let actionString = desc.components(separatedBy: ",")[0].components(separatedBy: "=").last | |
, let target = targetAction.value(forKey: "target") as? NSObject | |
{ |
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
// Polymorphic currying | |
enum Bar { | |
case weight(lbs: CGFloat) | |
} | |
func foo(_ valueA: String, _ valueB: Int) -> (Bar) -> () | |
{ | |
return { _bar in | |
switch _bar { |
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
class EnumString: NSObject { | |
let rawValue: String | |
init(rawValue: String = #function) { | |
self.rawValue = rawValue | |
} | |
static var abc: EnumString { return .init() } | |
static var defg: EnumString { return .init() } | |
static var hijk: EnumString { return .init() } |
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
class Finder<VIEW_TYPE: UIView> { | |
var foundView: VIEW_TYPE? | |
public func findView(with identifier: String) throws { | |
foundView = findView(with: identifier, parent: UIApplication.shared.keyWindow!) | |
if foundView == nil { | |
throw NSError() | |
} | |
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
// A possible technique for testing a json transfers to a struct properly | |
let json: [String: Any] = [ | |
"alpha" : "aaaa", | |
"beta" : 98, | |
"delta" : 23.7 | |
] | |
// the keys that we care about | |
enum ABCEnum: String { | |
case alpha |
NewerOlder