๋ชฉ๋กreference (2)

Focus On Develop ๐ŸคŸ๐ŸคŸ

[Swift] Class vs Struct

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ๋งค์šฐ ๊ธฐ๋ณธ์ด๋ฉด์„œ๋„, ๋งค์šฐ ์ค‘์š”ํ•œ Class์™€ Struct์— ๋Œ€ํ•ด์„œ ์ข€ ์‚ดํŽด๋ณด๋ ค๊ณ  ํ•ด์š”! ๋Œ์•„๋ณด๋‹ค ๋ณด๋‹ˆ, ์ด๋Ÿฐ Swift์— ๋Œ€ํ•ด ๊ธฐ๋ณธ์ด์ง€๋งŒ ๋งค์šฐ ์ค‘์š”ํ•œ ๋‚ด์šฉ๋“ค์„ ๋”ฐ๋กœ ๋‹ค๋ฃจ์ง€ ์•Š์•˜๋˜ ๊ฒƒ ๊ฐ™์•„์„œ ์ข€ ๋‹ค๋ฃจ๋ ค๊ณ ์š”!! ๐Ÿง‘‍๐Ÿ’ป ๋จผ์ € Struct์™€ Class๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ž„์˜๋กœ ๋งŒ๋“  "๋ฐ์ดํ„ฐ ํƒ€์ž…"์ด์—์š”. ๋ฐ์ดํ„ฐ๋ฅผ ํŠน์ • ์šฉ๋„์— ๋งž๊ฒŒ ๋ฌถ์–ด ํ‘œํ˜„ํ•˜๊ณ ์ž ํ• ๋•Œ, ๋‚ด๋ถ€์—์„œ ํ”„๋กœํผํ‹ฐ์™€ ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•ด์„œ ๊ตฌ์กฐํ™”๋œ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด ๋  ์ˆ˜ ์žˆ์–ด์š”. ๋จผ์ € ๊ฐ„๋žตํ•˜๊ฒŒ ๊ณตํ†ต์ ๊ณผ ์ฐจ์ด์ ์„ ์š”์•ฝํ•ด๋ณด๊ณ , ์ค‘์š”ํ•œ ์ฐจ์ด์ ์— ๋Œ€ํ•ด์„œ๋Š” ์ข€ ๋” ์‚ดํŽด๋ณผ๊ฒŒ์š”! ๊ณตํ†ต์  ๊ฐ’์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋กœํผํ‹ฐ ์ •์˜ ๊ฐ€๋Šฅ ๊ธฐ๋Šฅ ์‹คํ–‰์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ ์ •์˜ ๊ฐ€๋Šฅ initializer(์ƒ์„ฑ์ž) ์ •์˜ ๊ฐ€๋Šฅ extension ์„ ํ†ตํ•œ ํ™•์žฅ ๊ฐ€๋Šฅ protocol ์ฑ„ํƒ ๊ฐ€๋Šฅ..

[Swift] ARC (Automatic Reference Counting)

Swift์—์„œ๋Š” ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ๋ฅผ ์–ด๋–ป๊ฒŒ ํ• ๊นŒ์š”~? Swift์—์„œ ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜๋ฅผ ๋ฐฉ์ง€ํ•˜๊ณ  ์„ฑ๋Šฅ์ €ํ•˜๋ฅผ ๋ง‰๊ธฐ์œ„ํ•ด ARC ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”! ์ด ARC์— ๋Œ€ํ•ด์„œ ํ•œ๋ฒˆ ์•Œ์•„๋ณด๋ ค๊ณ  ํ•ด์š”! RC๋ž€ Reference Counting์˜ ์•ฝ์ž๋กœ ์• ํ”Œ์—์„œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ๋ผ๋Š” ๊ธฐ๋ณธ์ ์ธ Rule์ด๋ผ๋Š” ์ „์ œ๋ฅผ ๋‘ก๋‹ˆ๋‹ค. MRC๋ž€ Manual Reference Counting์˜ ์•ฝ์ž๋กœ Object-C์—์„œ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘! ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹น/ํ•ด์ œ ํ•ด์ค˜์•ผ ํ• ๋•Œ ์“ฐ๋Š” ๋ฐฉ๋ฒ•์ด๋ผ๊ณ  ํ•˜๋Š”๋ฐ, ์ด ๋ถ€๋ถ„์€ ์ฟจํ•˜๊ฒŒ ์š”์ •๋„๋กœ ํŒจ์Šคํ•ฉ๋‹ˆ๋‹ค.ใ…Ž ์ด๋ฏธ Swift๊ฐ€ ๋ณดํŽธํ™” ๋˜์—ˆ๊ณ , ์ € ๋˜ํ•œ Object-C๋Š” 1๋„ ๋ชจ๋ฅด๊ณ  ํ˜„์žฌ ์‚ฌ์šฉ๋„ ์•ˆํ•˜๊ธฐ ๋•Œ๋ฌธ..ใ…‹๐Ÿ‘๐Ÿ‘ ์ž ์ด์ œ ๋ณธ๋ก ์œผ๋กœ ๋“ค์–ด๊ฐ€์„œ, ARC๋ž€ Automatic Reference Counting์˜..