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
/** | |
* Bulletproof singletone constructor. Can be used with or | |
* without new, can be called from whatever (object method, | |
* standalone function). Works fine in strict mode | |
*/ | |
var Singletone = (function () { | |
var instance; | |
return function Construct_singletone () { | |
if (instance) { |
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
// - MARK: - Swift | |
let startTime = CACurrentMediaTime() | |
// Code to test | |
print("Runtime: \((CACurrentMediaTime() - startTime) * 1000) ms") | |
// MARK: - Obj-C | |
// Measuring runtime of the particular part of code | |
CFTimeInterval startTime = CACurrentMediaTime(); |
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
+ (instancetype)sharedInstance { | |
static id sharedInstance = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
sharedInstance = [[self alloc] init]; | |
}); | |
return sharedInstance; | |
} |
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
// MARK: Delegate approach | |
import UIKit | |
protocol ExampleViewModelDelegate: class { | |
func someEventDidOccur() | |
} | |
class ExampleViewModel { | |
weak var delegate: ExampleViewModelDelegate? |