Skip to content

Instantly share code, notes, and snippets.

View AliSoftware's full-sized avatar

Olivier Halligon AliSoftware

View GitHub Profile
@interface MyCell : UITableViewCell
+(CGSize)cellSizeForText:(NSString*)text;
@end
#import "UIView+NFCore.h" // "instantiateFromNib:"
@implementation MyCell
@AliSoftware
AliSoftware / 1-NoDependencyInjection.m
Last active December 28, 2015 14:09
Dependency injection concepts
// 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;
@AliSoftware
AliSoftware / oncetoken_reset_thread_risk.m
Last active December 25, 2015 06:49
Demo of a case where resetting onceToken can be non-thread-safe and dangerous
dispatch_once_t onceToken;
SomeClass* _sharedInstance;
+ (id)sharedInstance
{
dispatch_once(&onceToken, ^{ _sharedInstance = [SomeClass new]; });
return _sharedInstance;
}
- (void)tearDown
@AliSoftware
AliSoftware / async_test_crash_demo.m
Last active December 25, 2015 06:49
Demo of code executing even after a unit test has finished
- (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