๊ธ€ ์ž‘์„ฑ์ž: ๊ฐœ๋ฐœํ•˜๋Š” ํ›ˆ์ด

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’€๋‹ค๊ฐ€ ์ •์ˆ˜๋ฅผ Character ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด ์ƒ๊ฒผ๋Š”๋ฐ, ๋ฌธ์ž์—ด๋กœ ๋จผ์ € ๋ณ€ํ™˜ํ•œ ๋’ค์— Character๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ๊ฐ„ํŽธํ•˜๋‹ค.

๋ฐฉ๋ฒ• 1: ๋ฌธ์ž์—ด๋กœ ํ˜•๋ณ€ํ™˜

let num = 0
var numbers: [Character] = []

numbers.append(Character(String(num)))

print(numbers) // ["0"]

๋ฐฉ๋ฒ• 2: String Interpolation 

let num = 0
var numbers: [Character] = []

numbers.append(Character("\(num)"))

print(numbers) // ["0"]

 

String Interpolation์œผ๋กœ String์œผ๋กœ ์ผ๋‹จ ๋งŒ๋“ค๊ณ , Character ํƒ€์ž…์˜ ์ƒ์„ฑ์ž๋ฅผ ์ด์šฉํ•ด์„œ ํ˜•๋ณ€ํ™˜์„ ์ˆ˜ํ–‰ํ•œ๋‹ค.