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
import UIKit | |
// MARK: - Specification | |
protocol ViewType { | |
associatedtype ViewModel: ViewModelType | |
var viewModel: ViewModel { get } |
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
import Foundation | |
import SystemConfiguration.CaptiveNetwork | |
func getWiFiSsid() -> String? { | |
var ssid: String? | |
if let interfaces = CNCopySupportedInterfaces() as NSArray? { | |
for interface in interfaces { | |
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? { | |
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String | |
break |
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
import Foundation | |
func fatalError<T>(@autoclosure message: () -> String = "", file: StaticString = #file, line: UInt = #line) -> T { | |
fatalError(message(), file: file, line: line) | |
} | |
// Demo | |
protocol ResultType { |
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
import Foundation | |
func dispatch_async_batch(tasks: [() -> ()], limit: Int, completion: (() -> ())?) { | |
if tasks.count > 0 || completion != nil { | |
let q = dispatch_queue_create("dispatch_async_batch", DISPATCH_QUEUE_CONCURRENT); | |
let sema = dispatch_semaphore_create(limit); | |
dispatch_async(q, { | |
for task in tasks { | |
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER) |
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
import UIKit | |
import XCPlayground | |
// SKIP FOR NOW :) | |
protocol SmartCell { | |
associatedtype Model | |
static var reuseId: String { get } |
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
import UIKit | |
class BaseSimpleDataSource<Cell: ReusableView, Collection: CollectionType | |
where Collection.Index == Int, | |
Collection.Generator.Element: CollectionType, | |
Collection.Generator.Element.Index == Int, | |
Collection.Generator.Element.Generator.Element == Cell.Model>: NSObject { | |
typealias Item = Cell.Model |
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
import UIKit | |
import PureLayout | |
extension UINib { | |
func instantiateWithOwner<T: AnyObject>(owner: AnyObject?, options: [NSObject : AnyObject]? = nil, type: T.Type) -> T { | |
let objs = self.instantiateWithOwner(owner, options: options) | |
return objs.findFirst { $0 is T } as! 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
/// Cast the argument to the infered function return type. | |
func autocast<T>(some: Any) -> T? { | |
return some as? T | |
} | |
protocol Foo { | |
static func foo() -> Self | |
} | |
class Vehicle: Foo { |
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
import Foundation | |
protocol ServiceLocator { | |
func getService<T>(type: T.Type) -> T? | |
func getService<T>() -> T? | |
} | |
extension ServiceLocator { |
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
protocol ServiceLocator { | |
func getService<T>() -> T? | |
} | |
final class LazyServiceLocator: ServiceLocator { | |
/// Registry record | |
enum RegistryRec { | |
case Instance(Any) |