I hereby claim:
- I am AliSoftware on github.
- I am aligatr (https://keybase.io/aligatr) on keybase.
- I have a public key whose fingerprint is 172F 2268 1A5A BD88 4FFF D1B3 F6D2 6970 231A FBDE
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
struct Coordinator { | |
let window: UIWindow | |
let navCtrl: UINavigationController? | |
func start() { | |
presentWelcomeScreen() | |
} | |
private func presentWelcomeScreen() { | |
let vc = WelcomeScreenViewController() // Instanciate from code, XIB, Storyboard, whatever your jam is |
enum Crash: ErrorType { case Key(String) } | |
func kaboom(str: String) throws -> String { | |
throw Crash.Key(str) | |
} | |
// Crash with EXC_BAD_ACCESS, not every time but quite often | |
func test1() throws -> [String:[String]] { | |
return [ | |
"foo": try [kaboom("test1a"), kaboom("test1b")] | |
] |
protocol Fooable { | |
static var staticBigSelf: String { get } | |
static var staticSmallSelf: String { get } | |
var instanceBigSelf: String { get } | |
var instanceSmallSelf: String { get } | |
init() | |
} | |
extension Fooable { | |
static var staticBigSelf: String { return String(Self) } |
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()) { |
//: Playground - noun: a place where people can play | |
import Foundation | |
// This is a fake implementation mimicking the behavior of having a Localizable.string | |
// This is used here to be able to test the code easily in a Playground | |
func localize(key: String) -> String { | |
return [ | |
"alert.title": "Titre d'Alerte", | |
"alert.message": "Message d'Alerte", |
// 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 |
# Swift 2.0 | |
protocol AbstractAnimal : CustomStringConvertible { | |
// Abstract, to implement | |
var firstName: String { get set } | |
var lastName: String { get set } | |
// var fullName: String { get } // don't declare it this time! | |
} |
// For implementing the Promises pattern, I suggest http://promisekit.org | |
// But here we will build a very simple, naive and limited implementation just to show very basic concepts | |
import Foundation | |
///////////////////// | |
// Promise Pattern (very simplified and naive) | |
///////////////////// | |
class Promise<T> { |
// #!Swift-1.1 | |
import Foundation | |
// MARK: - (1) classes | |
// Solution 1: | |
// - Use classes instead of struct | |
// Issue: Violate the concept of moving model to the value layer | |
// http://realm.io/news/andy-matuschak-controlling-complexity/ |