This file contains hidden or 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
extension UIColor { | |
static func from(hex: String) -> UIColor? { | |
assert(hex.characters.first! == "#", "Maybe not a valid colour \(hex)") | |
var val = hex.substringFromIndex(hex.startIndex.advancedBy(1)) | |
switch val.characters.count { | |
case 3: val.appendContentsOf("f"); fallthrough | |
case 4: val = val.characters.map{"\($0)\($0)"}.joinWithSeparator("") | |
case 6: val.appendContentsOf("ff") | |
case 8: do {} | |
default: return nil // not proper format: #rgb, #rgba, #rrggbb, #rrggbbaa |
This file contains hidden or 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
//: Playground - noun: a place where people can play | |
import Foundation | |
public class JSON { | |
public static func toNSData(obj: AnyObject) -> NSData? { | |
return try? NSJSONSerialization.dataWithJSONObject(obj, options: NSJSONWritingOptions(rawValue: 0)) | |
} | |
public static func toJSONObj(obj: NSData) -> AnyObject? { |
This file contains hidden or 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 | |
extension Dictionary { | |
func JSONValue(path:String) -> AnyObject? { | |
let dict = self as! NSDictionary | |
return dict.JSONValue(path) | |
} | |
} |
This file contains hidden or 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 | |
extension String { | |
subscript(range: NSRange) -> String { | |
get { | |
let comp = self | |
let begin = comp.startIndex.advancedBy(range.location) | |
let sre = comp.substringWithRange(begin ..< begin.advancedBy(range.length)) | |
return sre |
This file contains hidden or 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
+ (void) debugStatement:(sqlite3_stmt *)statement | |
{ | |
for(int i=0; i<sqlite3_column_count(statement); i++) | |
{ | |
sqlite3_column_value(statement, i); | |
const char *name = sqlite3_column_name(statement, i); | |
const char *type = sqlite3_column_decltype(statement, i); | |
NSLog(@"%d %s %s", i, name, type); | |
} |