Skip to content

Instantly share code, notes, and snippets.

Avatar

Olivier Halligon AliSoftware

View GitHub Profile
View VariableCellSize.m
@interface MyCell : UITableViewCell
+(CGSize)cellSizeForText:(NSString*)text;
@end
#import "UIView+NFCore.h" // "instantiateFromNib:"
@implementation MyCell
View Promises.swift
// 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> {
View Protocol-Extensions.swift
# 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!
}
View L10n.swift
//: 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",
@AliSoftware
AliSoftware / async_test_crash_demo.m
Last active Dec 25, 2015
Demo of code executing even after a unit test has finished
View async_test_crash_demo.m
- (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
@AliSoftware
AliSoftware / oncetoken_reset_thread_risk.m
Last active Dec 25, 2015
Demo of a case where resetting onceToken can be non-thread-safe and dangerous
View oncetoken_reset_thread_risk.m
dispatch_once_t onceToken;
SomeClass* _sharedInstance;
+ (id)sharedInstance
{
dispatch_once(&onceToken, ^{ _sharedInstance = [SomeClass new]; });
return _sharedInstance;
}
- (void)tearDown
@AliSoftware
AliSoftware / 1-NoDependencyInjection.m
Last active Dec 28, 2015
Dependency injection concepts
View 1-NoDependencyInjection.m
// 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 / dict-release-crash.swift
Last active Feb 9, 2016
Crash with EXC_BAD_ACCESS on release
View dict-release-crash.swift
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")]
]
@AliSoftware
AliSoftware / ProtocolGenericsSelf.swift
Last active Feb 13, 2016
Use of "Self" vs "self" in "static var" + generic protocol implementation
View ProtocolGenericsSelf.swift
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) }
View keybase.md

Keybase proof

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: