Created
September 16, 2014 21:18
-
-
Save MaximShoustin/fac654a4d7b6e1e3375e to your computer and use it in GitHub Desktop.
Extension Helper
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 Double { | |
func format(f: String) -> String { | |
return NSString(format: "%\(f)f", self) | |
} | |
func toString() -> String { | |
return String(format: "%.1f",self) | |
} | |
} | |
extension String { | |
func split(splitter: String) -> Array<String> { | |
let regEx = NSRegularExpression(pattern: splitter, options: NSRegularExpressionOptions(), error: nil) | |
let stop = "SomeStringThatYouDoNotExpectToOccurInSelf" | |
let modifiedString = regEx.stringByReplacingMatchesInString (self, options: NSMatchingOptions(), | |
range: NSMakeRange(0, countElements(self)), | |
withTemplate:stop) | |
return modifiedString.componentsSeparatedByString(stop) | |
// return self.componentsSeparatedByString(splitter) | |
} | |
func startWith(find: String) -> Bool { | |
return self.hasPrefix(find) | |
} | |
func equals(find: String) -> Bool { | |
return self == find | |
} | |
func contains(find: String) -> Bool{ | |
if let temp = self.rangeOfString(find){ | |
return true | |
} | |
return false | |
} | |
func equalsIgnoreCase(find: String) -> Bool { | |
return self.lowercaseString == find.lowercaseString | |
} | |
func trim() -> String { | |
return self.stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet()) | |
} | |
func removeCharsFromEnd(count:Int) -> String{ | |
let stringLength = countElements(self) | |
let substringIndex = (stringLength < count) ? 0 : stringLength - count | |
return self.substringToIndex(advance(self.startIndex, substringIndex)) | |
} | |
func length() -> Int { | |
return countElements(self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment