๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ ‘๊ทผ์ œ์–ด, Access control Access Control, ์ ‘๊ทผ ์ œ์–ด ๋‹ค๋ฅธ ์†Œ์ŠคํŒŒ์ผ ๋ฐ ๋ชจ๋“ˆ์˜ ์ฝ”๋“œ์—์„œ, ์ฝ”๋“œ์˜ ์ผ๋ถ€์— ๋Œ€ํ•œ ์•ก์„ธ์Šค(์ ‘๊ทผ)์„ ์ œํ•œ Swift ์ ‘๊ทผ ์ œ์–ด ๋ชจ๋ธ์€ ๋ชจ๋“ˆ ๋ฐ ์†Œ์ŠคํŒŒ์ผ์˜ ๊ฐœ๋…์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ๋‹ค. ์ ‘๊ทผ์ œ์–ด๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด ์™ธ๋ถ€์—์„œ ๊ฐ์ฒด๋‚ด์˜ ์ž๋ฃŒ๋กœ์˜ ์ ‘๊ทผ์„ ์ œํ•œํ•˜๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ •,์กฐ์ž‘ํ•˜๋Š” ๋™์ž‘์€ ๋‚ด๋ถ€์— ๋‘๊ณ  ์ ‘๊ทผ(getter),์„ค์ •(setter)ํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋กœ ๊ฒฐ๊ณผ๋งŒ ๋ฐ›๋„๋ก ํ•˜๋Š” ๊ฐ์ฒด์˜ ์€๋‹‰ํ™”๋ฅผ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ด์ค€๋‹ค ๋ชจ๋“ˆ ์ฝ”๋“œ ๋ฐฐํฌ(code distribution)์˜ ๋‹จ์ผ ์œ ๋‹› Xcode์˜ ๊ฐ ๋นŒ๋“œ ๋Œ€์ƒ ( ์˜ˆ : ์•ฑ ๋ฒˆ๋“ค ๋˜๋Š” Framework )์€ Swift์—์„œ ๋ณ„๋„์˜ ๋ชจ๋“ˆ๋กœ ์ฒ˜๋ฆฌ ์†Œ์ŠคํŒŒ์ผ ๋ชจ๋“ˆ ๋‚ด์˜ ๋‹จ์ผ Swift์†Œ์Šค ์ฝ”๋“œ ํŒŒ์ผ (์‚ฌ์‹ค์ƒ ์•ฑ ๋˜๋Š” Framework๋‚ด์˜ ๋‹จ์ผ ํŒŒ์ผ) Access Levels, ์ ‘๊ทผ ๋ ˆ๋ฒจ o.. 2021. 12. 28.
Method Dispatch Method Dispatch ํ”„๋กœ๊ทธ๋žจ์ด ์–ด๋–ป๊ฒŒ ํ•ด๋‹น ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ํ• ์ง€ ์ •ํ•˜๋Š” ๊ฒƒ Static Dispatch vs Dynamic Dispatch 1. Static Dispatch = Direct Dispatch = Direct Call "์ปดํŒŒ์ผ ํƒ€์ž„"์— ํ˜ธ์ถœ๋  ํ•จ์ˆ˜๋ฅผ ๊ฒฐ์ • ์ปดํŒŒ์ผ ํƒ€์ž„์— ๊ฒฐ์ •์ด ๋‚˜๊ธฐ ๋•Œ๋ฌธ์— ์„ฑ๋Šฅ์ƒ ์ด์  Value Type์ธ ๊ตฌ์กฐ์ฒด, ์—ด๊ฑฐํ˜•์€ ์ƒ์†์„ ํ•  ์ˆ˜ ์—†๋‹ค๋Š” ํŠน์ง• ๋•Œ๋ฌธ์— ์˜ค๋ฒ„๋ผ์ด๋”ฉ์ด ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์—†๊ณ , ๋”ฐ๋ผ์„œ Static Dispatch๋ฅผ ์‚ฌ์šฉ 2. Dynamic Dispatch = Indirect Call "๋Ÿฐํƒ€์ž„"์— ํ˜ธ์ถœ๋  ํ•จ์ˆ˜๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค Swift์—์„œ๋Š” ํด๋ž˜์Šค๋งˆ๋‹ค ํ•จ์ˆ˜ ํฌ์ธํ„ฐ๋“ค์˜ ๋ฐฐ์—ด์ธ vTable(Virtual Dispatch Table)์ด๋ผ๋Š” ๊ฒƒ์„ ์œ ์ง€ ํ•˜์œ„ ํด๋ž˜์Šค๊ฐ€ ๋ฉ”์„œ๋“œ๋ฅผ.. 2021. 12. 6.
KVO, Key-Value Observing 1. KVC๋ž€? KVC, Key-Value Coding KVC๋ž€, ๊ฐ์ฒด์˜ ๊ฐ’์„ ์ง์ ‘ ๊ฐ€์ ธ์˜ค์ง€์•Š๊ณ , Key ๋˜๋Š” KeyPath ๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐ„์ ‘์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•˜๋Š” ๋ฐฉ๋ฒ• struct Person { var name : String } var person = Person(name:"lee") // ๊ฐ์ฒด์˜ ๊ฐ’ ์ง์ ‘ ๊ฐ€์ ธ์˜ค๊ธฐ let myName = person.name // KeyPath ๋ฅผ ์ด์šฉํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ let nameKeyPath = \\.Person.name let myName = person[keyPath: nameKeyPath] Key Path๋ฅผ ๋งŒ๋“œ๋Š”๋ฒ• Key Path ์ข…๋ฅ˜ KeyPath Read-only WritableKeyParh value type ์ธ์Šคํ„ด์Šค์— ์‚ฌ์šฉ ๊ฐ€๋Šฅ.. 2021. 12. 6.
Swift - ๊ณ ์ฐจํ•จ์ˆ˜, Higher-order function ๊ณ ์ฐจํ•จ์ˆ˜ ๊ณ ์ฐจํ•จ์ˆ˜(Higher-order function) : โ€˜๋‹ค๋ฅธ ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌ์ธ์ž๋กœ ๋ฐ›๊ฑฐ๋‚˜ ํ•จ์ˆ˜์‹คํ–‰์˜ ๊ฒฐ๊ณผ๋ฅผ ํ•จ์ˆ˜๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜โ€™๋ฅผ ๋œปํ•œ๋‹ค. ์Šค์œ„ํ”„ํŠธ์˜ ํ•จ์ˆ˜(ํด๋กœ์ €)๋Š” ์ผ๊ธ‰์‹œ๋ฏผ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•จ์ˆ˜์˜ ์ „๋‹ฌ์ธ์ž๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๊ณ  ํ•จ์ˆ˜์˜ ๊ฒฐ๊ณผ๊ฐ’์œผ๋กœ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ๊ณ ์ฐจํ•จ์ˆ˜์ด๋‹ค ์Šค์œ„ํ”„ํŠธ ํ‘œ์ค€๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ์œ ์šฉํ•œ ๊ณ ์ฐจํ•จ์ˆ˜ 1. map mapํ•จ์ˆ˜๋Š” ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์˜ ๊ธฐ์กด ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€ํ˜•(transform)ํ•˜์—ฌ ์ƒˆ๋กœ์šด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑ let numbers: [Int] = [0, 1, 2, 3, 4] var doubledNumbers = numbers.map({ (number: Int) -> Int in return number * 2 }) print(doubledNumbers) // [0, 2, 4, 6.. 2021. 2. 10.
Swift19 - ์ต์Šคํ…์…˜ Extensions Extensions add new functionality to an existing class, structure, enumeration, or protocol type. Extensions in Swift can: Add computed instance properties and computed type properties Define instance methods and type methods Provide new initializers Define subscripts Define and use new nested types Make an existing type conform to a protocol ์ต์Šคํ…์…˜์ด๋ž€? - ์ต์Šคํ…์…˜์€ ๊ตฌ์กฐ์ฒด, ํด๋ž˜์Šค, ์—ด๊ฑฐํ˜•, ํ”„๋กœํ† ์ฝœ ํƒ€์ž…์— ์ƒˆ๋กœ์šด.. 2021. 2. 10.
Swift18 - ํ”„๋กœํ† ์ฝœ Protocols A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol. In addition to specifying require.. 2021. 2. 10.