Swift

Swift4でjoinedが使えない

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入門者へおすすめ動画&書籍おすすめ!

  • この記事を書いた人

藤沢瞭介(Ryosuke Hujisawa)

りょすけと申します。18歳からプログラミングをはじめ、今はフロントエンドでReactを書いたり、AIの勉強を頑張っています。off.tokyoでは、ハイテクやガジェット、それからプログラミングに関する情報まで、エンジニアに役立つ情報を日々発信しています!

1
2
no image 3
4
5
6
7
8
9
10
no image 11
12
13
14
15
16
17
18
19
20
21
22
23

-Swift