Skip to content

Instantly share code, notes, and snippets.

@phamquochoan
phamquochoan / gist:386a775e98bac214483a
Last active Mar 23, 2016
Carthage build different targets with same name
View gist:386a775e98bac214483a

####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 Mar 27, 2015
UIColor from hex code - Swift
View UIColor from Hex 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 Mar 21, 2015
Increase or decrease enum's raw value by one point if it's kind of FloatingPoint or Integer
View Increase or decrease enum's raw value operators
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 Mar 21, 2015
Replace rawValue with custom operator
View Replace rawValue with custom operator
postfix operator .. { }
postfix func ..<T: RawRepresentable> (lhs: T) -> T.RawValue {
return lhs.rawValue
}
View HH:mm formatter for UITextField in Swift
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