iOS/Swift
Initializer / init(repeating:count:)
oreoOz
2023. 6. 6. 16:55
repeating과 count를 이용하여 초기화하는 방법!!!!!
init(
repeating repeatedValue: String,
count: Int
)
이는 String이나 Array에서 사용할 수 있는 초기화 방법입니다
Parameter의 종류는 다음과 같습니다.
repeatValue
반복될 string 문자열을 입력합니다.
count
입력한 숫자 Int 만큼 repeatValue의 문자열을 반복합니다.
다음은 Initializer 사용의 예시입니당.
let s = String(repeating: "ab", count: 10)
print(s)
// Prints "abababababababababab"
let fiveZs = Array(repeating: "Z", count: 5)
print(fiveZs)
//"결과값 : ["Z", "Z", "Z", "Z", "Z"]
https://developer.apple.com/documentation/swift/string/init(repeating:count:)-23xjt
init(repeating:count:) | Apple Developer Documentation
Creates a new string representing the given string repeated the specified number of times.
developer.apple.com