使用 Swift 从数组中创建一个以换行符 (\n) 分隔的字符串

Alu*_*num 3 arrays string ios swift

我在开发 iOS 应用程序时遇到一个问题,我想要实现的是从字符串数组创建单个字符串。该数组包含给定位置的地址,该地址是使用 的反向地理编码获得的CLGeocoder,这是为我提供字符串数组的代码:

let userCoordinates = CLLocation(latitude: mapView.userLocation.location!.coordinate.latitude, longitude: mapView.userLocation.location!.coordinate.longitude)

CLGeocoder().reverseGeocodeLocation(userCoordinates, completionHandler: {
    placemark, error in

    let reverseGeocodedLocation = placemark?.first?.addressDictionary?["FormattedAddressLines"] as? [String]
}
Run Code Online (Sandbox Code Playgroud)

reverseGeocodedLocation就我而言是:

["Apple Inc.", "Cupertino, CA  95014", "United States"]
Run Code Online (Sandbox Code Playgroud)

结果字符串应分隔数组中的字符串,并以多行格式呈现它们,如下所示:

Apple Inc.
Cupertino, CA 95014
United States
Run Code Online (Sandbox Code Playgroud)

我尝试在网上搜索解决方案,我发现这段代码应该可以做到这一点,这可能是解决方案:

print("\n".join(reverseGeocodedLocation.map({$0})))
Run Code Online (Sandbox Code Playgroud)

但编译器说:

无法使用“([String]?)”类型的参数列表调用“join”

Hen*_*Lee 5

if let reverseGeocodedLocation = reverseGeocodedLocation {
    print(reverseGeocodedLocation.joinWithSeparator("\n"))
}
Run Code Online (Sandbox Code Playgroud)

作为答案而不是评论。

斯威夫特 3/4:

reverseGeocodedLocation.joined(separator: "\n")
Run Code Online (Sandbox Code Playgroud)