Useful extensions

extension for String

extension String {
  func stringByTrimmingLeadingAndTrailingWhitespace() -> String {
    let leadingAndTrailingWhitespacePattern = "(?:^\\s+)|(?:\\s+$)"
 
    if let regex = NSRegularExpression(pattern: leadingAndTrailingWhitespacePattern, options: .CaseInsensitive, error: nil) {
      let range = NSMakeRange(0, countElements(self))
      let trimmedString = regex.stringByReplacingMatchesInString(self, options: .ReportProgress, range:range, withTemplate:"$1")
 
      return trimmedString
    } else {
      return self
    }
  }
}

extension for UIColor

extension UIColor {
    class func trueColor() -> UIColor {
        return UIColor(red: 0.1882, green:0.6784, blue:0.3882, alpha:1.0)
    }
    
    class func falseColor() -> UIColor {
        return UIColor(red:0.7451, green:0.2275, blue:0.1922, alpha:1.0)
    }
}

你可能感兴趣的:(Useful extensions)