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

前端 未结 6 2359
暗喜
暗喜 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:38

    For anyone in swift 3.x its now something like this this will work like a charm.

    var string = String(repeating: "a", count: 5)
    

提交回复
热议问题