Skip to content

Instantly share code, notes, and snippets.

Last active Sep 11, 2015
What would you like to do?
// Split
extension String {
public func split(
maxSplit: Int = .max,
allowEmptySlices: Bool = false,
@noescape isSeparator: ((Character) throws -> Bool)) rethrows -> [String] {
return try self.characters.split(
allowEmptySlices: allowEmptySlices,
isSeparator: isSeparator)
public enum StringSplitError : ErrorType {case MissingCharacter}
public func split(characterString: String) throws -> [String] {
guard let c = characterString.characters.first else {throw StringSplitError.MissingCharacter}
return self.split{$0 == c}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment