Skip to content

Instantly share code, notes, and snippets.

@phamquochoan
phamquochoan / gist:386a775e98bac214483a
Last active March 23, 2016 03:40
Carthage build different targets with same name

####1. Framework Dog - for iOS ######-- target 1: Labrador ######-- target 2: GoldenRetriever Target 2 have a custom Swift Compiler Flag: -D FUR (I still don't know what -D mean)

class Dog {
  #if FUR
 var furLength: Double = 10
@phamquochoan
phamquochoan / UIColor from Hex Swift
Created March 27, 2015 02:45
UIColor from hex code - Swift
convenience init(rgba: String) {
var red: CGFloat = 0.0
var green: CGFloat = 0.0
var blue: CGFloat = 0.0
var alpha: CGFloat = 1.0
let formattedCode = rgba.stringByReplacingOccurrencesOfString("#", withString: "")
let formattedCodeLength = count(formattedCode)
if formattedCodeLength != 3 && formattedCodeLength != 4 && formattedCodeLength != 6 && formattedCodeLength != 8 {
fatalError("invalid color")
@phamquochoan
phamquochoan / Increase or decrease enum's raw value operators
Created March 21, 2015 10:50
Increase or decrease enum's raw value by one point if it's kind of FloatingPoint or Integer
postfix func ++ <T: RawRepresentable, V: FloatingPointType>(lhs: T) -> V {
return (lhs.rawValue as! V) + 1
}
postfix func -- <T: RawRepresentable, V: FloatingPointType>(lhs: T) -> V {
return (lhs.rawValue as! V) - 1
}
postfix func ++ <T: RawRepresentable, V: IntegerType>(lhs: T) -> V {
return (lhs.rawValue as! V) + 1
@phamquochoan
phamquochoan / Replace rawValue with custom operator
Created March 21, 2015 10:49
Replace rawValue with custom operator
postfix operator .. { }
postfix func ..<T: RawRepresentable> (lhs: T) -> T.RawValue {
return lhs.rawValue
}
lazy var timeFormatter: NSNumberFormatter! = {
var formatter = NSNumberFormatter()
formatter.numberStyle = .NoStyle
formatter.groupingSize = 2
formatter.groupingSeparator = ":"
formatter.usesGroupingSeparator = true
formatter.maximumFractionDigits = 0
formatter.minimumIntegerDigits = 4
formatter.maximumIntegerDigits = 4
return formatter