Swift - ์•„์Šคํ‚ค์ฝ”๋“œ ๋ณ€ํ™˜ํ•˜๊ธฐ

2022. 9. 27. 14:35ใ†ios

Swift - ์•„์Šคํ‚ค์ฝ”๋“œ ๋ณ€ํ™˜ํ•˜๊ธฐ

 

 

์•„์Šคํ‚ค์ฝ”๋“œ๋ฅผ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ .asciiValue(), UnicodeScalar()๊ฐ€ ์žˆ๋Š”๋ฐ์š” 

 

์ผ๊ด€์„ฑ์„ ๋งž์ถ”๊ธฐ ์œ„ํ•ด UnicodeScalar()๋กœ ํ†ต์ผํ•ด์„œ ์•Œ์•„๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

Character -> ์•„์Šคํ‚ค ๊ฐ’

UnicodeScalar("A").value ->  65

 

.value๋ฅผ ํ†ตํ•ด์„œ ์ ‘๊ทผํ•˜๋ฉด ๋ฐ˜ํ™˜๊ฐ’์ด UInt32์ด๊ธฐ ๋•Œ๋ฌธ์— ์—ผ๋‘ํ•ด์„œ ๋ณ€ํ™˜์‹œ์ผœ์„œ ์‚ฌ์šฉํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

 

 

์•„์Šคํ‚ค ๊ฐ’ -> Character

UnicodeScalar(65)! -> "A"

 

๋ฐ˜ํ™˜๊ฐ’์ด ์˜ต์…”๋„์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ•์ œ์–ธ๋ž˜ํ•‘์„ ํ•ด์คฌ๋‹ค๋Š” ์ 

์ด๋•Œ ๋ฐ˜ํ™˜๊ฐ’์ด Scalar์ด๊ธฐ ๋•Œ๋ฌธ์— String์ด ์š”๊ตฌํ•˜๋Š” ๊ฒƒ์ด๋ผ๋ฉด String์œผ๋กœ ๊ฐ์‹ธ์ฃผ๋ฉด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค

 

 

+ ์ถ”๊ฐ€

apple ๊ณต์‹๋ฌธ์„œ

UnicodeScalar๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ธ์ž๋กœ UInt์˜ ํƒ€์ž…์ด๋‚˜ String, Scalarํƒ€์ž…๋งŒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. (String์„ for๋ฌธ ๋Œ๋ฆด ๋•Œ character๋กœ ๋ฐ˜ํ™˜๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ์ฃผ์˜ํ•ด์•ผ ํ•จ) -> String์œผ๋กœ ๊ฐ์‹ธ๋ฉด ํ•ด๊ฒฐ!

 

 

 

'ios' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Swift - Set ํ†บ์•„๋ณด๊ธฐ  (0) 2022.09.28
Swift - 2์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ  (0) 2022.09.27
iOS - Realm  (0) 2022.09.19
Swift - ํด๋ž˜์Šค ์ƒ์†๊ณผ ์žฌ์ •์˜  (1) 2022.07.06
swift - ์‹ฑ๊ธ€ํ†ค ํŒจํ„ด  (0) 2022.07.05