Swift

Swift4でjoinedが使えない

2018年7月9日

Swift4でjoinedが使えない

 

エラー内容

 

$ swift build
Compile Swift Module 'PerfectTemplate' (2 sources)
/opt/bitnami/apache2/htdocs/PerfectTemplate/Sources/main.swift:36:12: error: ambiguous reference to member 'joined()'
    print( uploads.joined(separator: ",") )
           ^~~~~~~
Swift.Sequence:25:17: note: found this candidate
    public func joined() -> FlattenSequence<Self>
                ^
Swift.Sequence:16:17: note: found this candidate
    public func joined<Separator>(separator: Separator) -> JoinedSequence<Self> where Separator : Sequence, Separator.Element == Self.Element.Element
                ^
Swift.Sequence:16:17: note: found this candidate
    public func joined(separator: String = default) -> String
                ^
Swift.Collection:25:17: note: found this candidate
    public func joined() -> FlattenCollection<Self>
                ^
Swift.BidirectionalCollection:25:17: note: found this candidate
    public func joined() -> FlattenBidirectionalCollection<Self>
                ^
Swift.BidirectionalCollection:16:17: note: found this candidate
    public func joined(separator: String = default) -> String
                ^
error: terminated(1): /usr/share/swift/usr/bin/swift-build-tool -f /opt/bitnami/apache2/htdocs/PerfectTemplate/.build/debug.yaml main

 

解決

 

let array = request.postParams
print( type(of:"\(array.map({ String(describing: $0) }).joined(separator: ""))") )
//String

 

Pocket
LinkedIn にシェア

-Swift

Copyright© off.tokyo , 2021 All Rights Reserved Powered by AFFINGER5.