Skip to content

Instantly share code, notes, and snippets.

@MarcoMig
MarcoMig / ClassA.swift
Last active December 8, 2017 03:38
Swift: Async callback block pattern example
//ClassA it's the owner of the callback, he will trigger the callback when it's the time
class ClassA {
//The property of that will be associated to the ClassB callback
var callbackBlock : ((error : NSError?, message : String?, adress : String? ) -> Void)?
init() {
//Do Your staff
}
//Define your function with the clousure as a parameter
// Creates a UIColor from a Hex string.
func colorWithHexString (hex:String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString
if (cString.hasPrefix("#")) {
cString = cString.substringFromIndex(1)
}
if (countElements(cString) != 6) {
return UIColor.grayColor()