Skip to content

Instantly share code, notes, and snippets.

@wanbok
Last active August 29, 2015 14:18
Show Gist options
  • Save wanbok/ce854325a471dd15cc1e to your computer and use it in GitHub Desktop.
Save wanbok/ce854325a471dd15cc1e to your computer and use it in GitHub Desktop.
Swift, Joining (Implicitly Unwrapped) Optional Strings with a joiner
extension String {
func join(strings: String!... ) -> String {
return self.join(strings.filter({ $0?.isEmpty == false }).map {$0 as String})
}
}
@wanbok
Copy link
Author

wanbok commented Apr 2, 2015

Using like this:

var contry: String! = nil
var city: String! = ""
var address: String! = "Nowon"
var detailAddress: String! = "Gongneung-dong"

let combinedAddress = " ".join(contry, city, address, detailAddress)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment