Created
August 24, 2014 03:21
-
-
Save anonymous/1d0f2bbb397596f88664 to your computer and use it in GitHub Desktop.
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 String { | |
func split(separator:String) -> [String] { | |
return self.componentsSeparatedByString(separator) | |
} | |
func split(separator:String) -> (String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 2) ? (pieces[0], pieces[1]) : nil | |
} | |
func split(separator:String) -> (String, String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 3) ? (pieces[0], pieces[1], pieces[2]) : nil | |
} | |
func split(separator:String) -> (String, String, String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 4) ? (pieces[0], pieces[1], pieces[2], pieces[3]) : nil | |
} | |
func split(separator:String) -> (String, String, String, String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 5) ? (pieces[0], pieces[1], pieces[2], pieces[3], pieces[4]) : nil | |
} | |
func split(separator:String) -> (String, String, String, String, String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 6) ? (pieces[0], pieces[1], pieces[2], pieces[3], pieces[4], pieces[5]) : nil | |
} | |
func split(separator:String) -> (String, String, String, String, String, String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 7) ? (pieces[0], pieces[1], pieces[2], pieces[3], pieces[4], pieces[5], pieces[6]) : nil | |
} | |
func split(separator:String) -> (String, String, String, String, String, String, String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 8) ? (pieces[0], pieces[1], pieces[2], pieces[3], pieces[4], pieces[5], pieces[6], pieces[7]) : nil | |
} | |
func split(separator:String) -> (String, String, String, String, String, String, String, String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 9) ? (pieces[0], pieces[1], pieces[2], pieces[3], pieces[4], pieces[5], pieces[6], pieces[7], pieces[8]) : nil | |
} | |
func split(separator:String) -> (String, String, String, String, String, String, String, String, String, String)? { | |
let pieces:[String] = self.split(separator) | |
return (pieces.count == 10) ? (pieces[0], pieces[1], pieces[2], pieces[3], pieces[4], pieces[5], pieces[6], pieces[7], pieces[8], pieces[9]) : nil | |
} | |
} | |
if let (hello, world) = "Hello, world".split(", ") { | |
println(hello) | |
println(world) | |
} | |
if let (hello, world) = "Hello, world, omg".split(", ") { | |
println(hello) | |
println(world) | |
} | |
if let (first, last, birthday) = "Bob, Quone, January 1st 1987".split(", ") { | |
println(first) | |
println(last) | |
println(birthday) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment