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 | |
struct FrontScreenViewmodel { | |
var hello = "there" | |
} | |
// Builds the ViewControllers, and injects the ViewModels | |
class Factory { | |
let viewModelFactory = ViewModelFactory() |
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
/* Usage | |
let log = OSLog(subsystem: "deep-secrets", category: "cookie-recipes") | |
let signpostID = log.beginSignpost(withName: "signpost name") | |
... Do work ... | |
log.endSignpost(withName: "signpost name" , signpostId: signpostId) | |
Signposts can also be started w objects instead of SignpostIDs when scope is an issue |
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 UIImageView { | |
func setImage(from url: URL, withPlaceholder placeholder: UIImage? = .none, withCache cache:NSCache<NSURL,UIImage>? = .none) -> URLSessionDataTask? { | |
if let cached = cache?.object(forKey: url as NSURL) { | |
self.image = cached | |
return .none | |
} | |
self.image = placeholder | |
let task = URLSession.shared.dataTask(with: url) { (data, _, _) in |
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 Result<T> { | |
case success(T) | |
case error(Error) | |
} | |
struct ToDo : Codable { | |
var id: Int | |
var userId: Int | |
var title:String | |
var completed:Bool |
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
let field = [0,0,0,0,1,0,0,0,1,0,1,1,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1] | |
var memo:[Int:[Int:Bool]] = [0:[:]] | |
func bounce(startingSpeed:Int, startingIndex:Int, field:[Int]) -> Bool { | |
// Many base cases. We must still be on the runway. | |
// We must land on a place with 0 (no spikes) | |
// Use a double dictionary as the memo. Store true/false. 1 dimension for each changing intput!!!! |
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
+ (BOOL)resolveClassMethod:(SEL)name { | |
NSString *classname = NSStringFromClass([self class]); | |
NSString *selectorString = [NSString stringWithFormat:@"crazyClass%@",classname]; | |
NSLog(@"string is %@", selectorString); | |
SEL ourSelector = NSSelectorFromString(selectorString); | |
if (name == ourSelector) { | |
// adding class method to meta-class | |
Class ourClass = object_getClass(NSClassFromString(classname)); | |
class_addMethod(ourClass, ourSelector, (IMP)crazyClassMethod, "@v:@"); |
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
+ (BOOL)resolveInstanceMethod:(SEL)aSEL { | |
NSString *classname = NSStringFromClass([self class]); | |
NSString *selectorString = [NSString stringWithFormat:@"insaneInstance%@",classname]; | |
SEL ourSelector = NSSelectorFromString(selectorString); | |
if (aSEL == ourSelector) { | |
class_addMethod([self class], aSEL, (IMP)insaneInstanceMethod, "v@:"); | |
return YES; | |
} | |
return [super resolveInstanceMethod:aSEL]; | |
} |
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 unwrap<T:Any>(dictionary:[String : AnyObject], key:String, defaultValue:T) -> T { | |
let value = dictionary[key] as? T ?? defaultValue | |
return value as T | |
} | |
// Can be curried inside a init?(json:NSDictionary) function | |
let stringAtKey:(String) -> String = { key in | |
return unwrap(dictionary , key:key, defaultValue:"") |
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
hello() { name in | |
... some code ... | |
anotherMethod { anotherThing in | |
.. I'm nested in two closures | |
} | |
} |
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 XCPlayground | |
import AudioKit | |
let osc = AKWhiteNoise() | |
let filter = AKLowPassFilter(osc, cutoffFrequency: 200, resonance: 3) | |
osc.start() | |
let verb = AKReverb(filter) | |
verb.dryWetMix = 0.5 |
NewerOlder