Does Swift init(count:, repeatedValue:) work?

前端 未结 6 2361
暗喜
暗喜 2021-02-18 15:04

Tested this from the reference: https://developer.apple.com/documentation/swift

var string = String(count: 5, repeatedValue: \"a\")
// string is \"aaaaa\"
         


        
6条回答
  •  孤街浪徒
    2021-02-18 15:29

    For the benefit of future searchers: as of Swift 3, use init(repeating:count:).

    let sososo = String(repeating: "so", count: 3)
    

提交回复
热议问题