Noah's Dev Log

Written by
@[SeungHyun]

๐Ÿ‘จโ€๐Ÿ’ป 25์‚ด ๋Œ€ํ•™์ƒ ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค.

๏ฃฟ Swift๋ฅผ ํ™œ์šฉํ•œ iOS๊ฐœ๋ฐœ์— ๊ด€์‹ฌ์ด ๋งŽ์ง€๋งŒ

๐Ÿ›  ๊ธฐ์ˆ ์„ ๊ฐ€๋ฆฌ์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค.๐Ÿ˜Š

๋ธ”๋กœ๊ทธ ์ด์ „ ๊ณต์ง€

https://noah-ios.dev ๋กœ ๋ธ”๋กœ๊ทธ๋ฅผ ์ด์ „ํ•˜์˜€์Šต๋‹ˆ๋‹ค. Swift, ๊ฐœ๋ฐœ, ๊ฒฝํ—˜๊ณผ ๊ด€๋ จ๋œ ์ด์•ผ๊ธฐ๋ฅผ ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค. ๋งŽ์€ ๊ด€์‹ฌ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ™‡โ€โ™‚๏ธ๐Ÿ™‡

Apple์˜ ๊ณผ๊ฑฐ Process memory ๊ด€๋ฆฌ ๋ชจ๋ธ์„ ์•Œ์•„๋ณด์ž

์šด์˜์ฒด์ œ๊ฐ€ ํ”„๋กœ์„ธ์Šค๋ณ„๋กœ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์„ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•œ ํ•™์Šต์˜ ์ผํ™˜์œผ๋กœ Apple์˜ ๊ณผ๊ฑฐ Macintosh Operating System์˜ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ ๋ชจ๋ธ์„ ํ˜„๋Œ€ ํ”„๋กœ์„ธ์Šค ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ ๋ชจ๋ธ๊ณผ ๋น„๊ตํ•ด๊ฐ€๋ฉฐ, stack, heap, text, ๊ธ€๋กœ๋ฒŒ ๋ณ€์ˆ˜ GVAR, BSS์˜ ์—ญํ• ์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด์ž. Inside Macintosh: Memory Clasโ€ฆ

Thank you Jonathan Rasmusson!!

WWDC 2016 UnderStanding Swift Performance์„ ๋ณด๊ณ  ๋‚œ ํ›„์— ์ž˜๋ชป ์ดํ•ดํ•˜๊ณ  ์žˆ๋˜ ๋ถ€๋ถ„(๋ถ€๋„๋Ÿฝ์ง€๋งŒ Value Type์€ ๋ฌด์กฐ๊ฑด Stack์—๋งŒ ํ• ๋‹น๋˜๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.)์„ ๋ฐ”๋กœ ์žก๊ธฐ ์œ„ํ•ด ๋ฉ”๋ชจ๋ฆฌ ๋งต์„ ํ™•์ธํ•ด๋ณด๋ฉฐ Value Type์ด ๋ฌด์กฐ๊ฑด Stack์—๋งŒ ํ• ๋‹น๋˜๋Š” ๊ฒƒ์ด ์•„๋‹˜์„ ์ €๋ฒˆ ํฌ์ŠคํŠธ๋ฅผ ํ†ตํ•ด ์กฐ์‚ฌํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ง€๋‚œ๋ฒˆ โ€ฆ

Value Type์€ ๋ฌด์กฐ๊ฑด Stack์—๋งŒ ํ• ๋‹น๋ ๊นŒ?

WWDC 2016 UnderStanding Swift Performance ์„ธ์…˜์„ ๋ณด๊ณ  ์ž˜๋ชป ์ดํ•ดํ•˜๊ณ  ์žˆ๋˜ ๋ถ€๋ถ„์„ ๋ฐ”๋กœ ์žก๊ธฐ์œ„ํ•ด ์‹คํ—˜์„ ํ†ตํ•ด ๋‹ค์‹œ ํ’€์–ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์œ„ ์„ธ์…˜์„ ์•„๋ž˜์˜ ํฌ์ŠคํŠธ๋ฅผ ํ†ตํ•ด ์ •๋ฆฌํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ๊ด€์‹ฌ์žˆ๋Š” ๋ถ„๋“ค์€ ์•„๋ž˜์˜ ๋งํฌ๋ฅผ ์ฐธ์กฐํ•ด์ฃผ์„ธ์š”! Swift ์„ฑ๋Šฅ ์ดํ•ดํ•˜๊ธฐ struct-class ๋˜ํ•œ Value Type์ด ์ •๋ง Stack์—๋งŒ ํ• ๋‹นโ€ฆ

[weak self] ๋ฌด์กฐ๊ฑด ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ๋งž๋Š”๊ฑธ๊นŒ? ๐Ÿค”

ํด๋กœ์ ธ์—์„œ self๋ฅผ ์บก์ณํ•  ๋•Œ ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์ˆœํ™˜ ์ฐธ์กฐ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์•ฝํ•œ ์ฐธ์กฐ๋กœ ํด๋กœ์ ธ ๋‚ด๋ถ€์—์„œ ํ•ด๋‹น ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ• ๋•Œ ์ž…๋‹ˆ๋‹ค. ํด๋กœ์ ธ์—์„œ ์•ฝํ•œ ์ฐธ์กฐ๋ฅผ ์ด์šฉํ•ด ํŠน์ • ์ธ์Šคํ„ด์Šค๋ฅผ ์บก์ณํ•˜์ง€ ์•Š์œผ๋ฉด (์—ฌ๊ธฐ์„œ๋Š” self๋ฅผ ์บก์ณํ•œ๋‹ค๊ณ  ๊ฐ€์ •) self๊ฐ€ ํ•ด์ œ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฌ๊ณ  self๋Š” ํด๋กœ์ ธ๊ฐ€ ํ•ด์ œ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฌ๋Š” strong referenโ€ฆ

Git์˜ commit id๋Š” ์–ด๋–ป๊ฒŒ ์ƒ์„ฑ๋ ๊นŒ?

์—ฌ๋Ÿฌ๋ถ„ ์•ˆ๋…•ํ•˜์„ธ์š”! Noah์ž…๋‹ˆ๋‹ค. ํ˜น์‹œ Git์„ ์‚ฌ์šฉํ•˜๋ฉด์„œ commit id๋ฅผ ๋ณด์‹  ์ ์ด ์žˆ๋‚˜์š”? ์šฐ๋ฆฌ๋Š” commit id๋กœ ํŠน์ • ๋ฒ„์ „์„ ๊ฐ€๋ฆฌ์ผœ commit์„ ๋˜๋Œ๋ฆฌ๊ธฐ๋„ ํ•˜๊ณ , ํŠน์ • commit์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋˜๋Œ๋ฆฌ๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ด commit id๋Š” ์–ด๋–ป๊ฒŒ ํ•ด์„œ ๋งŒ๋“ค์–ด์ง€๋Š” ๊ฑธ๊นŒ์š”? Q. ์„œ๋ฒ„์—์„œ ๊ณ ์œ ํ•œ id๋ฅผ ๋ถ€์—ฌํ•ด์ฃผ๋‚˜์š”..?๐Ÿง A. Git์€ โ€ฆ

Array - ๋ฐฐ์—ด

์•ˆ๋…•ํ•˜์„ธ์š” Noah์ž…๋‹ˆ๋‹ค :) ์˜ค๋Š˜์€ Swift์˜ ์ž๋ฃŒ๊ตฌ์กฐ ์ค‘ ๋ฐฐ์—ด์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค๐Ÿ˜€ ๋ฐฐ์—ด์€ ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ์— ์—ฐ์†๋˜์–ด์žˆ๋Š” ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋กœ ๋…ผ๋ฆฌ์ ์ธ ์ˆœ์„œ์™€ ๋ฌผ๋ฆฌ์ ์ธ ์ˆœ์„œ๊ฐ€ ๊ฐ™๋‹ค๋Š” ํŠน์ง•์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐฐ์—ด์€ ํŠน์ • ์š”์†Œ์˜ ์กฐํšŒ๊ฐ€ ์•„์ฃผ ๋น ๋ฅด๋‹ค๋Š” ํŠน์ง•์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํŠน์ • ์š”์†Œ๋ฅผ ์กฐํšŒํ•  ๋•Œ ์ˆœํšŒ(traversing)ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ๋ฐฐ์—ด์˜ ํŠน์ง•โ€ฆ

Observer Pattern

์•ˆ๋…•ํ•˜์„ธ์š” Noah์ž…๋‹ˆ๋‹ค :) ์˜ค๋Š˜์€ Gang of Four ์†Œํ”„ํŠธ์›จ์–ด ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํ–‰์œ„ ํŒจํ„ด์— ์†ํ•˜๋Š” Observer Pattern ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. iOS์—์„œ Observer Pattern์€ Foundation framework์˜ NotificationCenter, KVO(Key Value Observing), Property Obโ€ฆ

Swift ์„ฑ๋Šฅ ์ดํ•ดํ•˜๊ธฐ struct-class

์•ˆ๋…•ํ•˜์„ธ์š” Noah์ž…๋‹ˆ๋‹ค :) ์ข‹์€ ๊ฐœ๋ฐœ์ž๋Š” ์ข‹์€ ์ฝ”๋“œ๋ฅผ ์งœ์•ผ ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ œ๊ฐ€ ์ƒ๊ฐํ•˜๋Š” ์ข‹์€ ์ฝ”๋“œ๋ž€, ํŒ€์›๋“ค์ด ๋ณด๊ธฐ์— ์ข‹์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ , ์•ˆ์ •์ ์ด๊ณ  ์†๋„๊ฐ€ ๋น ๋ฅธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด ๊ฒฐ๊ณผ์ ์œผ๋กœ ์•ฑ์„ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ์ข‹์€ ๊ฒฝํ—˜์„ ์•ˆ๊ฒจ์ฃผ๋Š” ๊ฒƒ์ด ์ข‹์€ ์ฝ”๋“œ๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ์ข‹์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•œ ์ดˆ์„์œผ๋กœ Swift ์„ฑ๋Šฅ ์ดํ•ดํ•˜๊ธฐ๋ผ๋Š” ์ œ๋ชฉ์œผโ€ฆ

iOS ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ EntryPoint

์•ˆ๋…•ํ•˜์„ธ์š” Noah์ž…๋‹ˆ๋‹ค :) ์˜ค๋Š˜์€ iOS ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ง„์ž…์ (Entry Point) ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋ฉฐ, ๊ธฐ๋ณธ์ ์ธ ์•ฑ์˜ ๊ตฌ์กฐ์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค๐Ÿ˜ƒ Entry Point (์ง„์ž…์ ) ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์€ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋‚˜ ์šด์˜์ฒด์ œย ๋“ฑ์— ์˜ํ•ด ์ •์˜๋œ ๊ด€์šฉ๋ช…์„ ํ†ตํ•œ, ์ง€์ •๋œ ์ด๋ฆ„์œผ๋กœ ์‹œ์ž‘๋  ์ˆ˜ ์žˆ๋‹ค. ๋งŽ์€ ์–ธ์–ด์—์„œ(ํŠนํžˆ C) ์ด ์ง€์ •๋œ ์ด๋ฆ„์€ย ์ด๋ผ๊ณ  ๋ถˆ๋ฆฌโ€ฆ