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
- (void)setUp | |
{ | |
[super setUp]; | |
[MagicalRecord setupCoreDataStackWithInMemoryStore]; | |
} | |
- (void)tearDown | |
{ | |
[MagicalRecord cleanUp]; // cleans up the CoreData stack to be ready for a clean state for the next tests | |
// Note: any code after this line that would try to use CoreData will obviously fail |
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
dispatch_once_t onceToken; | |
SomeClass* _sharedInstance; | |
+ (id)sharedInstance | |
{ | |
dispatch_once(&onceToken, ^{ _sharedInstance = [SomeClass new]; }); | |
return _sharedInstance; | |
} | |
- (void)tearDown |
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
// No dependency injection at all. | |
// Instead of having independant modules, we have a strong dependency between the Controller, the ContactService and the View | |
@interface Contact : NSObject | |
@property NSString* name; | |
// … | |
@end | |
@interface ContactService : NSObject | |
- (void)fetchAllContactsWithCompletion:(void(^)(NSArray* contacts))completion; |
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
@interface MyCell : UITableViewCell | |
+(CGSize)cellSizeForText:(NSString*)text; | |
@end | |
#import "UIView+NFCore.h" // "instantiateFromNib:" | |
@implementation MyCell |
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
// #!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/ |
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 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> { |
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
# 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! | |
} |
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
//: 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", |
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()) { |
OlderNewer