直接上代码。
Swift 1
var fullName = "First Last"
var fullNameArr = split(fullName) {$0 == " "}
var firstName: String = fullNameArr[0]
var lastName: String? = fullNameArr.count > 1 ? fullNameArr[1] : nil
Swift 2
Swift 2: Xcode 7 beta 1
let fullName = "First Last"
let fullNameArr = split(fullName.characters){$0 == " "}.map{String($0)}
fullNameArr[0] // First
fullNameArr[1] // Last
Swift 2: Xcode 7 beta 2
let fullName = "First Last"
let fullNameArr = split(fullName.characters){$0 == " "}.map(String.init)
fullNameArr[0] // First
fullNameArr[1] // Last
Swift 2: Xcode 7 beta 5
let fullName = "First Last"
let fullNameArr = fullName.split {$0 == " "}
fullNameArr[0] // First
fullNameArr[1] // Last
Swift 2: Xcode 7
let fullName = "First Last"
let fullNameArr = fullName.characters.split {$0 == " "}
fullNameArr[0] // First
fullNameArr[1] // Last