Swift 23

[ Swift ] Class Singleton ๐Ÿ†š Struct Singleton

์‹ฑ๊ธ€ํ„ด ํŒจํ„ด์‹ฑ๊ธ€ํ„ด ํŒจํ„ด์€ ์†Œํ”„ํŠธ์›จ์–ด ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํ•˜๋‚˜๋กœ, ๋‹จ ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค๋งŒ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.๋”ฐ๋ผ์„œ ํ•œ ๋ฒˆ ์ƒ์„ฑ๋˜๋ฉด ๊ทธ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„๋งŒ ๊ณ„์† ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ๋ฉ”๋ชจ๋ฆฌ ๋‚ญ๋น„๋ฅผ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๊ณ , ์‚ฌ์šฉ ์‹œ ์ด๋ฏธ ์ƒ์„ฑ๋˜์–ด ์žˆ๋Š” ์ธ์Šคํ„ด์Šค ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์†๋„๋„ ๋น ๋ฆ…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ „์—ญ์ ์œผ๋กœ ์ƒ์„ฑ๋˜์–ด ๋งŽ์€ ๊ณณ์—์„œ ์‚ฌ์šฉ๋˜๋ฏ€๋กœ ์—ฌ๋Ÿฌ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜๋Š” ๋“ฑ์˜ ๋ฉ€ํ‹ฐ์Šค๋ ˆ๋”ฉ ํ™˜๊ฒฝ์—์„œ ๋™์‹œ์„ฑ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹คํ–‰ํžˆ swift์—์„œ๋Š” ์ดˆ๊ธฐํ™” ์‹œ์ ์„ ๋ฏธ๋ฃฌ(lazily) static ํ”„๋กœํผํ‹ฐ๋ฅผ ํ†ตํ•ด ์ธ์Šคํ„ด์Šค๋ฅผ thread-safetyํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.The free function dispatch_once is no longer available in Swift. In Swift, you can use la..

Swift 2025.01.10

[ Swift ] Swift๋ž€?

Swift Swift is a general-purpose programming language that's approachable for newcomers and powerful for experts. It is fast, modern, safe, and a joy to write.์œ„ ๊ธ€์€ Swift.org์—์„œ ๊ฐ€์žฅ ๋จผ์ € ๋ณผ ์ˆ˜ ์žˆ๋Š” Swift ์†Œ๊ฐœ๊ธ€์ด๋‹ค. Swift๋Š” ์ ‘๊ทผ์„ฑ์ด ์ข‹๊ณ  ๊ฐ•๋ ฅํ•œ ๋ฒ”์šฉ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ด๋ฉฐ, ๋น ๋ฅด๋ฉฐ ํ˜„๋Œ€์ ์ด๊ณ  ์•ˆ์ „ํ•˜์—ฌ ์ฆ๊ฒ๊ฒŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค. interactive programming languageSwift์—์„œ ๊ฐ•์กฐ๋˜๋Š” ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ์ƒํ˜ธ์ž‘์šฉ์ด๋‹ค. ์ปดํŒŒ์ผ ์–ธ์–ด์ž„์—๋„, ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์ตœ์ ํ™”๋˜์–ด์žˆ์–ด ๋งˆ์น˜ ์Šคํฌ๋ฆฝํŠธ ์–ธ์–ด์ฒ˜๋Ÿผ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ƒํ˜ธ์ž‘์šฉํ•˜๋ฉฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•  ์ˆ˜ ์žˆ๋‹ค.์ปดํŒŒ์ผ..

Swift 2023.10.08

[ Swift ] zip(_:_:)

Documentation /Swift /Swift Standard Library /Collections /zip(_:_:) zip(_:_:) func zip( _ sequence1: Sequence1, _ sequence2: Sequence2 ) -> Zip2Sequence where Sequence1 : Sequence, Sequence2 : Sequence ๋‘ ๊ฐœ์˜ sequence๋กœ ๊ตฌ์„ฑํ•œ sequence ์Œ์„ ๋งŒ๋“œ๋Š” ํ•จ์ˆ˜์ด๋‹ค. Array, String, Range์ฒ˜๋Ÿผ Sequence ํ”„๋กœํ† ์ฝœ์„ ์ฑ„ํƒํ•œ ํƒ€์ž…์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์˜จ๋‹ค. ์ฆ‰, ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ํƒ€์ž…์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๊ฐ€์ง„๋‹ค ํŠœํ”Œ sequence ๋ฐ˜ํ™˜ zip์„ ์‚ฌ์šฉํ•ด ๋‘ sequence๋ฅผ ํ•ฉ์น˜๋ฉด ๊ฐ ์›์†Œ๋“ค์ด ๋™์ผํ•œ ์ธ๋ฑ์Šค ์›์†Œ๋“ค๊ณผ ์ง์„ ์ง€์–ด ํŠœํ”Œ ํƒ€์ž…์˜ Z..

Swift 2023.10.08

[ Swift ] isCase | isLowercase | isUppercase

isCase ํ•ด๋‹น Character์˜ ๋Œ€์†Œ๋ฌธ์ž ๋ณ€ํ™˜์ด ๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋Š” ํ”„๋กœํผํ‹ฐ์ด๋‹ค. String์ด ์•„๋‹ˆ๋ผ Character์˜ ์ธ์Šคํ„ด์Šค ํ”„๋กœํผํ‹ฐ๋ผ๋Š” ์ ์„ ์ฃผ์˜ํ•˜์ž. ๋Œ€์†Œ๋ฌธ์ž๊ฐ€ ์žˆ๋Š” ์˜์–ด๋Š” ture์ด์ง€๋งŒ ํ•œ๊ธ€, ์•„์ด์ฝ˜, ํŠน์ˆ˜๋ฌธ์ž ๋“ฑ์€ false์ด๋‹ค. let english = "a" let korean = "๊ฐ€" let icon = "๐Ÿงš๐Ÿป‍โ™€๏ธ" let half = "½" if english.first!.isCased { print(english) } // Prints "a" if korean.first!.isCased { print(korean) } if icon.first!.isCased { print(icon) } if half.first!.isCased { print(half) } isLowe..

Swift 2023.10.04

[ Swift ] print(_:separator:terminator:)

print(_:separator:terminator:) func print( _ items: Any..., separator: String = " ", terminator: String = "\n" ) ์ฃผ์–ด์ง„ ์•„์ดํ…œ์˜ ํ…์ŠคํŠธ ํ‘œํ˜„์„ ํ‘œ์ค€ ์ถœ๋ ฅํ•œ๋‹ค. items๋ฅผ ์ œ์™ธํ•œ ๋‹ค๋ฅธ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๊ธฐ๋ณธ๊ฐ’์ด ์„ค์ •๋˜์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ ๊ฐ’์„ ์ „๋‹ฌํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. Items items์€ Any ํƒ€์ž…์œผ๋กœ, ํƒ€์ž…๊ณผ ์•„์ดํ…œ์˜ ๊ฐœ์ˆ˜์— ์ƒ๊ด€์—†์ด ํ…์ŠคํŠธ๋กœ ํ‘œํ˜„๋˜์–ด ์ถœ๋ ฅ๋œ๋‹ค. items๋Š” String(item)๊ณผ ๊ฐ™์€ ์ž‘์—…์„ ์ž๋™์œผ๋กœ ํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ํƒ€์ž… ๋ณ€ํ™˜์„ ํ•ด์ฃผ์ง€ ์•Š์•„๋„ ๋œ๋‹ค let number: Int = 120 print(number) // Prints "120" seperator separator์€ ์—ฌ๋Ÿฌ ์•„์ดํ…œ์ด ์žˆ์„..

Swift 2023.10.04

[ Swift ] ํ”„๋กœํ† ์ฝœ ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

Swift๋Š” ํ”„๋กœํ† ์ฝœ ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ 2015๋…„ ํ”„๋กœํ† ์ฝœ Extension์ด ๋„์ž…๋œ Swift 2.0 ๋ฒ„์ „์ด ๋ฐœํ‘œ๋˜๋ฉฐ Apple์€ Swift๊ฐ€ ํ”„๋กœํ† ์ฝœ ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด๋ผ ์„ ์–ธํ–ˆ๋‹ค. ๋”ํ•ด ํ”„๋กœํ† ์ฝœ ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ ์ฐธ์กฐ ํƒ€์ž…์ธ ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ณด๋‹ค ๊ฐ’ ํƒ€์ž…์„ ๋” ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ, ์˜ค๋ฅ˜๋ฅผ ์ค„์ผ ๋ฐฉ์•ˆ์ด๋ผ ์†Œ๊ฐœํ–ˆ๋‹ค. ์ด์ œ ์Šค์œ„ํ”„ํŠธ์—์„œ๋Š” ํด๋ž˜์Šค์—์„œ ํ–ˆ๋˜ ๊ฒƒ์ฒ˜๋Ÿผ ๊ตฌ์กฐ์ฒด์™€ ์—ด๊ฑฐํ˜•์— ์บก์Šํ™”, ์ถ”์ƒํ™”, ์ ‘๊ทผ ์ œ์–ด ๋“ฑ์˜ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ฐธ์กฐ ํƒ€์ž…์˜ ์ฐธ์กฐ ๋ฌธ์ œ์—์„œ ๋” ์ž์œ ๋กœ์šธ ์ˆ˜ ์žˆ๊ณ  ๋‹ค์ค‘์ƒ์†๊ณผ ๋” ๋‚˜์€ ์ถ”์ƒํ™” ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ๊ตฌํ˜„ ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค. ํ”„๋กœํ† ์ฝœ ํ”„๋กœํ† ์ฝœ์ด๋ž€ ํŠน์ • ์ž‘์—…์— ๋งž๋Š” ๋ฉ”์„œ๋“œ์™€ ํ”„๋กœํผํ‹ฐ๋ฅผ ์ •์˜ํ•˜๋Š” ์ฒญ์‚ฌ์ง„์ด๋‹ค. ํด๋ž˜์Šค๋Š” ํด๋ž˜์Šค๋งŒ ์ƒ์†ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๊ณผ ๋‹ค๋ฅด๊ฒŒ, ํ”„๋กœํ† ์ฝœ์€ ํด๋ž˜์Šค, ๊ตฌ์กฐ์ฒด, ์—ด๊ฑฐํ˜•์ด..

Swift 2023.09.24

[ Swift ] Serialization์ด๋ž€?

๊ฒ€์ƒ‰์„ ํ†ตํ•ด ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ถ€์ •ํ™•ํ•  ์ˆ˜๋„ ์žˆ๊ณ  ์ถ”ํ›„ ์ถ”๊ฐ€ ๊ณต๋ถ€๋ฅผ ํ†ตํ•ด ๋‚ด์šฉ์ด ๋ณ€๊ฒฝ๋  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. Serialization์ด๋ž€? Serializtion์„ ๋ฒˆ์—ญํ•˜๋ฉด '์ง๋ ฌํ™”'์ด๋‹ค. ์ง๋ ฌํ™”๋ž€ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งํ•˜์ž๋ฉด ์–ด๋–ค ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฅธ ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค. ์ด ํ˜•ํƒœ๊ฐ€ ์ง๋ ฌ์ (์‹œ๊ฐ„ ์ˆœ์ฐจ์ )์ด๋ผ ์ง๋ ฌํ™”ํ•œ๋‹ค๊ณ  ํ‘œํ˜„ํ•œ๋‹ค. ์กฐ๊ธˆ ๋” ๊ธธ๊ฒŒ ์„ค๋ช…ํ•˜์ž๋ฉด ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ ๋˜๋Š” ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ์ถ”ํ›„์— ์ €์žฅ๋  ์ˆ˜ ์žˆ๊ฑฐ๋‚˜ ์ „์†ก๋  ์ˆ˜ ์žˆ๋Š”, ๋˜๋Š” ์žฌ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ๋Š” ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ณผ์ •์ด๋‹ค. ์ด์— ๋ฐ˜๋Œ€๋˜๋Š” ๊ฐœ๋…์€ Deserialization์ด๋‹ค. ๋ฒˆ์—ญํ•˜๋ฉด '์—ญ์ง๋ ฌํ™”'๋กœ, ์–ด๋– ํ•œ ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜๋œ ๊ฒƒ์„ ์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. Serialization์˜ ์˜ˆ์‹œ๋ฅผ ๋ณด๋ฉด ์กฐ๊ธˆ ๋” ์™€๋‹ฟ๋Š”๋‹ค. ์•ฑ ..

Swift 2023.01.18
728x90