Skip to content

Instantly share code, notes, and snippets.

View kazuhiro4949's full-sized avatar

Kazuhiro Hayashi kazuhiro4949

View GitHub Profile
@kazuhiro4949
kazuhiro4949 / UIColor+Hex.swift
Created May 4, 2016 06:37
convert rgb to UIColor object
extension UIColor {
/**
convert rgb to UIColor object
*/
class func color(color: UInt32, alpha : CGFloat = 1.0) -> UIColor {
let r = CGFloat((color & 0xFF0000) >> 16) / 255.0
let g = CGFloat((color & 0x00FF00) >> 8) / 255.0
let b = CGFloat(color & 0x0000FF) / 255.0
return UIColor(red:r,green:g,blue:b,alpha:alpha)
}
@kazuhiro4949
kazuhiro4949 / IntRawValueEnumerable.swift
Last active May 4, 2016 05:55
It make enum return the array of cases
/**
adapt to enum which is Int Raw Value.
It make enum return the array of cases
#### Example
```
enum SomeEnum: IntRawValueEnumerable {
case AAA
case BBB
}
@kazuhiro4949
kazuhiro4949 / Regex.swift
Last active May 7, 2016 06:38
Swift Regex wrapper snippet. ( supporting version 2.0+ )
/**
#### Example
if case Regex("^regular\s.+$") = "regular expression" {
return true
}
switch "regular expression" {
case Regex("^regular\s.+$"):
print("match ^regular\s.+$")
case Regex("^regurar\s.+$"):