我已经尝试加入一些[String!]
. 所以我这样做:
extension String {
func join(strings: String!... ) -> String {
return self.join(strings.filter({ $0?.isEmpty == false }).map {$0 as String})
}
}
var country: String! = nil
var city: String! = ""
var address: String! = "Nowon"
var detailAddress: String! = "Gongneung-dong"
let combinedAddress = " ".join(country, city, address, detailAddress)
但是,它似乎仍然很复杂。我该如何优化这个?