ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฐ˜์‘ํ˜•

ios-og


๐Ÿ•น View Controller


๐ŸŽฏ View Controller๋ž€?


  • View Controller๋Š” iOS ์•ฑ์˜ ๊ฐ€์žฅ ๊ธฐ์ดˆ๊ฐ€ ๋˜๋Š” ๋นŒ๋”ฉ ๋ธ”๋ก์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ์•ฑ์€ ์ตœ์†Œ ํ•œ ๊ฐœ์˜ View Controller๋ฅผ ๊ฐ€์ง€๋ฉฐ ์ผ๋ฐ˜์ ์œผ๋กœ ์—ฌ๋Ÿฌ๊ฐœ์˜ View Controller๋ฅผ ๊ฐ–๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

    ํ•˜๋‚˜์˜ view controller๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ํ•˜๋‚˜์˜ UI ๋˜๋Š” ์Šคํฌ๋ฆฐ(a single User Interface or screen)์„ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ UI์™€ ๋ชจ๋ธ(underlying data)๋“ค ์‚ฌ์ด์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

    ์˜ˆ์‹œ๋ฅผ ํ†ตํ•ด ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!


    class MainViewController: UIViewController
    {
        @IBOutlet weak var textLabel:UILabel?
    
        override func viewDidLoad()
        {
            super.viewDidLoad()
    
            textLabel?.text = "Click the button..."
        }
    
        @IBAction func onButtonTap(sender: UIButton)
        {
            textLabel?.text = "Hello world!"
        }
    }

    ์œ„์˜ ์˜ˆ์‹œ๋ฅผ ์ž์„ธํžˆ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค โ˜บ๏ธ

    ์šฐ์„  MainViewController๋ผ๋Š” ViewController๋ฅผ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. view controller๋Š” UIViewController๋ฅผ ์ƒ์†๋ฐ›์Šต๋‹ˆ๋‹ค. ์ด ํด๋ž˜์Šค๋Š” Optional UILabel ํƒ€์ž…์ธ ํ”„๋กœํผํ‹ฐ textLabel์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

    ํ”„๋กœํผํ‹ฐ์ธ textLabel์€ outlet์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ outlet์˜ ์‚ฌ์ „์  ์˜๋ฏธ๋Š” ์ถœ๊ตฌ, ๋ฐฐ์ถœ๊ตฌ, ํ‘œํ˜„์˜ ์ˆ˜๋‹จ ๋“ฑ์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ์š”, @IBOutlet์€


    'InterfaceBuilder'๋ฅผ ์‚ฌ์šฉํ•ด์„œ UI์—์„œ 'label๊ณผ outlet connnection์„ ๋งŒ๋“ค์ˆ˜ ์žˆ๋‹ค'


    ๋ผ๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค. ์ด ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด textLabel?.text์—์„œ .text์™€ ๊ฐ™์€ ๋ ˆ์ด๋ธ”์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๊ทธ ๋‹ค์Œ ๋ฉ”์†Œ๋“œ์ธ viewDidLoad๋ฅผ ๋ณด๋ฉด override๊ฐ€ ๋˜์–ด์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ์š”, ์ƒ์† ๋ฐ›์€ ๋ฉ”์†Œ๋“œ๋ผ๋Š” ์˜๋ฏธ์ด๊ธฐ ๋•Œ๋ฌธ์— UIViewController์—์„œ ์ด๋ฏธ ์ •์˜๋˜์–ด ์žˆ์„ ๊ฒƒ์ด๋ผ๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ฉ”์†Œ๋“œ๋Š” view controller life cycle์˜ ์ผ๋ถ€์ด๋ฉฐ view controller์˜ ์ผ๋ฐ˜์ ์ธ ์‹œ์ž‘์ ์ด๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๋งˆ์ง€๋ง‰์œผ๋กœ ๋ฉ”์†Œ๋“œ์ธ onButtonTap(sender:)๋Š” @IBAction์œผ๋กœ ์ •์˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์œ„์˜ IBOutlet๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Interface Builder๋ฅผ ํ†ตํ•ด ์ž‘๋™ํ•˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ ๋‹จ์ˆœํžˆ ์—ฐ๊ฒฐ์„ ์˜๋ฏธํ•˜๋Š” Outlet๊ณผ ๋‹ค๋ฅด๊ฒŒ ์–ด๋–ค ๋™์ž‘์„ ์ผ์œผํ‚จ๋‹ค๋Š” ์ธก๋ฉด์—์„œ Action์ด๋ผ๋Š” ๋„ค์ด๋ฐ์ด ๋ถ™์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.


  • ๋ชจ๋“  view controller์—๋Š” view property๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฒฐ๊ตญ view controller๋ผ๋Š” ๊ฒƒ์€ view๋“ค์˜ controller๋ผ๊ณ  ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ์—์„œ๋Š” UIViewController ํด๋ž˜์Šค์˜ view property๋ฅผ ํ†ตํ•ด view์— ์ ‘๊ทผ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ๋ฅผ ํ†ตํ•ด ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!



    ์œ„์˜ ๊ทธ๋ฆผ์„ ๋ณด๋ฉด View Controller ์•ˆ์—๋Š” ํ”„๋กœํผํ‹ฐ๋กœ Table View๋ฅผ ๊ฐ–๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ Table View ์•ˆ์—๋Š” Item Cell์ด๋ผ๋Š” ์š”์†Œ๊ฐ€ ์กด์žฌํ•˜๊ณ  ๊ทธ ์•ˆ์— ๋‹ค์‹œ Content View๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์ด Content View๋ถ€ํ„ฐ ์‚ดํŽด๋ณด๋ฉด ContentView๋Š” ์•„๋ž˜ ๋ ˆ์ด๋ธ”๋“ค์˜ Super View๊ฐ€ ๋˜๋ฉฐ, ๋ ˆ์ด๋ธ”์ด๋‚˜ ๋ฒ„ํŠผ, ์ธ๋„ค์ผ ๋“ฑ์€ Sub View๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ฃผ์˜ํ•  ์ ์€ View๋ผ๋Š” ์ด๋ฆ„์ด ๋ถ™์€ ์š”์†Œ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ฒ„ํŠผ ๋“ฑ๋„ view๋กœ ์ดํ•ดํ•ด์•ผํ•œ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค.

    ์ด์ œ๋ถ€ํ„ฐ ์กฐ๊ธˆ๋” ์ž์„ธํžˆ View Controller์— ๋Œ€ํ•ด ์ดํ•ดํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐ŸŽฏ


๐Ÿ“ Views, Storyboards, MVC and Controllers


  • ๋ฐ”๋กœ ์œ„์—์„œ view๋ผ๋Š” ๊ฒƒ์€ view controller์—์„œ ํ”„๋กœํผํ‹ฐ๋กœ ์กด์žฌํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์ด์•ผ๊ธฐํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋Œ€๋กœ ๋งํ•˜๋ฉด ๋ชจ๋“  view controller๋Š” view ํ”„๋กœํผํ‹ฐ๋ฅผ ๊ฐ–๋Š” ๊ฒƒ์ด๊ณ  controller๋Š” ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํŠธ๋ฆฌ ๊ตฌ์กฐ์˜ ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ๊ฐ–๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

    ๊ทธ๋ž˜์„œ iOS์˜ View Controller๋ฅผ ํ•™์Šตํ•˜๋‹ค๋ณด๋ฉด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ด๋Ÿฐ ์งˆ๋ฌธ์ด ๋– ์˜ค๋ฅด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.


    "๊ทธ๋ž˜์„œ view controller๋Š” MVC ์ค‘ View์ธ๊ฐ€ Controller์ธ๊ฐ€?"


    ๊ฒฐ๋ก ๋ถ€ํ„ฐ ์ด์•ผ๊ธฐ ํ•˜๋ฉด, view controller๋Š” view์ธ ๋™์‹œ์— controller์ž…๋‹ˆ๋‹ค(์›๋ฌธ์—์„œ๋Š” mix๋ผ๊ณ  ํ‘œํ˜„ํ•˜๋Š”๋ฐ ํ—ˆ๋ฌดํ•œ๋“ธ..). iOS์—์„œ๋Š” MVC๋ฅผ ์นผ๊ฐ™์ด ๋‚˜๋ˆ„๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ view controller ์•ˆ์— View์™€ Controller๋ผ๋Š” ๊ฐœ๋…์„ ํ•จ๊ป˜ ๋ฌถ์—ˆ์Šต๋‹ˆ๋‹ค.

    ์˜ˆ์‹œ๋กœ UITableViewController๋ฅผ ๋ณด๋ฉด ์ด ํด๋ž˜์Šค๋Š” ์Šคํฌ๋ฆฐ์— UI ํ…Œ์ด๋ธ”์„ ๋ณด์—ฌ์ฃผ๋Š” ๋™์‹œ์— ๋’ท๋‹จ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ์ฝ”๋ฉ˜ํŠธ๋ฅผ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.


    The dual role of the view controller is often criticized, and for good reason. Itโ€™s easy to dump a whole lot of code into a view controller. Youโ€™d let the view controller do everything in your appโ€™s UI, from organizing the view, to networking, user interaction, and controlling data models. This often results in whatโ€™s called Massive View Controller ...


    view controller๋Š” View์˜ ์—ญํ• ๊ณผ Controller์˜ ์—ญํ• ์„ ๋ชจ๋‘ ๊ฐ–๊ธฐ ๋•Œ๋ฌธ์— ๋„ˆ๋ฌด ๋งŽ์€ ๊ธฐ๋Šฅ๋“ค์ด ํ•œ ๊ณณ์— ๋ชจ์ผ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๊ณ , ๊ฐ์ฒด์ง€ํ–ฅ์˜ ํŠน์„ฑ์ƒ ํŠน์ • ํ•˜๋‚˜์˜ ๊ฐ์ฒด๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์€ ๊ถŒํ•œ๊ณผ ์ฑ…์ž„์„ ๊ฐ–๋Š” ๊ฒƒ์€ ๊ฑด๊ฐ•ํ•˜์ง€ ๋ชปํ•œ(?) ๊ตฌ์กฐ๊ฐ€ ๋˜๊ธฐ ์‰ฌ์šธ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์„ ํ”ผํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค๋Š” ์ ์„ ์ง€์ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

    ๋˜ํ•œ ์•„๋ž˜์˜ ์ฝ”๋ฉ˜ํŠธ ์—ญ์‹œ ํ•จ๊ป˜ ์ฝ์–ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.


    In practical iOS development, you donโ€™t create your UIs manually with Swift code. Itโ€™s more productive to use XIBs or Storyboards with Interface Builder, to visually build UIs. Interface Builder also has helpful tools to create responsive layouts for different iPhone device models and screen sizes.


    iOS ๊ฐœ๋ฐœ์—์„œ UI๋ฅผ Swift code๋กœ ์ˆ˜๋™ ๊ตฌํ˜„ ํ•˜์ง€ ์•Š๊ณ  XIB๋‚˜ ์Šคํ† ๋ฆฌ๋ณด๋“œ๋ฅผ ํ†ตํ•ด์„œ ๊ตฌํ˜„ํ•œ๋‹ค๋Š” ๊ฒƒ์ธ๋ฐ ์ด๊ฒƒ์€ ๋…ผ์Ÿ ๊ฐ€๋Šฅํ•œ ํ‘œํ˜„์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ™œ์šฉํ•  ๋•Œ์˜ ์žฅ๋‹จ์ ๊ณผ ์ฝ”๋“œ๋ฅผ ํ™œ์šฉํ•œ UI ๊ฐœ๋ฐœ์˜ ์žฅ๋‹จ์ ์ด ๋ช…ํ™•ํžˆ ์กด์žฌํ•˜๋ฏ€๋กœ ๊ฒฝ์šฐ์— ๋”ฐ๋ผ ์„ ํ˜ธ๋˜๋Š” ๋ฐฉ์‹์ด ๋‹ค๋ฅด๊ณ , ๋งŽ์€ ํ˜„์—…์—์„œ ์Šคํ† ๋ฆฌ๋ณด๋“œ๋ณด๋‹ค ์ฝ”๋“œ๋ฅผ ํ™œ์šฉํ•ด UI๋ฅผ ๊ทธ๋ฆฐ๋‹ค๊ณ  ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

    ํ˜น์‹œ XIB๋‚˜ Storyboard๊ฐ€ ๋ฌด์—‡์ธ์ง€ ํ—ท๊ฐˆ๋ฆฌ์‹œ๋Š” ๋ถ„๋“ค์„ ์œ„ํ•ด ๊ฐ€๋ณ๊ฒŒ ์„ค๋ช…ํ•˜๊ณ  ๋„˜์–ด๊ฐ€๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.


    XIB: XML ๊ธฐ๋ฐ˜์˜ UI ํŒŒ์ผ์ž…๋‹ˆ๋‹ค. ํ•˜๋‚˜์˜ UI์— ๋Œ€ํ•œ ์ •๋ณด๋“ค์„ ๋‹ด๊ณ  ์žˆ์œผ๋ฉฐ ์ผ๋ฐ˜์ ์œผ๋กœ view๋‚˜ view controller์— ์—ฐ๊ฒฐ๋ฉ๋‹ˆ๋‹ค.

    Storyboard: ์Šคํ† ๋ฆฌ๋ณด๋“œ๋Š” XIB์™€ ๋น„์Šทํ•œ ๊ฐœ๋…์œผ๋กœ ํ•˜๋‚˜ ์ด์ƒ์˜ UI์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค. segue๋ผ๋Š” ํ™”๋ฉด์ „ํ™˜ ๊ธฐ๋ฒ•์„ ํ†ตํ•ด view controller๊ฐ„ ์ „ํ™˜์ด ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.


    ๋‘ ๊ฐœ๋…์˜ ๊ฐ€์žฅ ํฐ ์ฐจ์ด๋Š” ์Šคํ† ๋ฆฌ๋ณด๋“œ๊ฐ€ ์ผ๋ฐ˜์ ์œผ๋กœ 2๊ฐœ ์ด์ƒ์˜ view controller๋ฅผ ๋‹ด๋Š”๋‹ค๋Š”๋ฐ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ XIB๋Š” ํ•˜๋‚˜์˜ ๋ทฐ๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๋ฐ˜๋ฉด Storyboard๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ทฐ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ „ํ™˜์— ๋Œ€ํ•œ ๊ฐœ๋…์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.

    ํ•˜๋‚˜ ์ถ”๊ฐ€๋กœ ์ฒจ์–ธํ•˜์ž๋ฉด, XIB์—์„œ ์ค‘์š”ํ•œ ๊ฐœ๋…์ด File's Owner๋ผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. File's Owner๋Š” ๋Ÿฐํƒ€์ž…์— XIB๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ํด๋ž˜์Šค๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋ง ๊ทธ๋Œ€๋กœ Interface Builder file์„ "own(์†Œ์œ )"ํ•˜๋Š” ๊ฒƒ์ธ๋ฐ ์ด ์—ฐ๊ฒฐ์ด ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ์™€ XIB๋ฅผ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    ๐Ÿง ๊ทธ๋Ÿผ NIB๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

    XIB๋Š” ์œ„์—์„œ ์–ธ๊ธ‰ํ•œ๋Œ€๋กœ ํŽธ์ง‘ ๊ฐ€๋Šฅํ•œ XML ํ˜•์‹์˜ Interface Builder ํŒŒ์ผ์ž…๋‹ˆ๋‹ค. NIB๋Š” ๋ฐฐํฌ ๊ฐ€๋Šฅํ•œ ๋ฐ”์ด๋„ˆ๋ฆฌ ํฌ๋งท์˜ ํŒŒ์ผ๋กœ app binary package์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.


๐Ÿ–‡ UI๋ฅผ ์ฝ”๋“œ์— ์—ฐ๊ฒฐํ•˜๊ธฐ


  • ์ผ๋ฐ˜์ ์œผ๋กœ UI์™€ view controller๋ฅผ ์—ฐ๊ฒฐํ•  ๋•Œ control ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅธ ์ƒํƒœ๋กœ ๋Œ์–ด๋‹น๊ฒจ ์—ฐ๊ฒฐ์„ ํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ํ˜น์€ hierarchy์—์„œ inspector tab์— ์ง์ ‘ ์—ฐ๊ฒฐํ•  ์ˆ˜๋„ ์žˆ๊ฒ ์ฃ ? ํ•˜์ง€๋งŒ ์ด ๋ฐฉ๋ฒ•์€ Storyboard์—์„œ ์‚ฌ์šฉํ•  ๋•Œ์˜ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ๋งŒ์•ฝ XIB์— ์—ฐ๊ฒฐํ•œ๋‹ค๊ณ  ํ•˜๋ฉด view controller์— ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ File's Owner์— ์—ฐ๊ฒฐํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.


    ๐Ÿง ์™œ textLabel ๋“ฑ์„ ์„ ์–ธํ•  ๋•Œ ๋””ํดํŠธ๊ฐ€ weak var(์•ฝํ•œ ์ฐธ์กฐ)๋กœ ์„ ์–ธ๋ ๊นŒ?

    ์•ฝํ•œ ์ฐธ์กฐ์˜ ๊ฐœ๋…์„ ๋ฉ”๋ชจ๋ฆฌ์ ์ธ ๊ด€์ ์ด ์•„๋‹ˆ๋ผ ์กฐ๊ธˆ ๋‹จ์ˆœํ™” ์‹œ์ผœ์„œ ์ƒ๊ฐํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฐ„๋‹จํžˆ ๋งํ•˜๋ฉด ์ด๊ฒƒ์€ UI ์š”์†Œ(์—ฌ๊ธฐ์„œ๋Š” Label)๊ณผ view controller๊ฐ€ ์•ฝํ•œ ๊ฒฐํ•ฉ์„ ํ–ˆ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. Strongํ•œ retain cycle์ด ์ƒ๊ฒจ memory leak์ด ์ƒ๊ธฐ๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๊ฒƒ์ด์ฃ .

    weak type์ผ ๊ฒฝ์šฐ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ํ•ด์ œ๋˜๋Š” ์‹œ์ ์— ์–ธ์ œ nil๋กœ ๊ฐ’์ด ๋ณ€๊ฒฝ๋  ์ง€ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ํ•ญ์ƒ ์˜ต์…”๋„ ํƒ€์ž…์œผ๋กœ ์„ ์–ธ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ viewDidLoad()๊ฐ€ ์‹คํ–‰๋˜๊ธฐ ์ „์— outlet ํ”„๋กœํผํ‹ฐ๋“ค์€ nil ๊ฐ’์„ ๊ฐ–์Šต๋‹ˆ๋‹ค. ์•„์šธ๋ › ๊ฐ’์„ ์˜ต์…”๋„๋กœ ์„ค์ •ํ•˜๋ฏ€๋กœ์จ ์ด ๊ฐ’์ด nil์ผ ๋•Œ ์‹ค์ˆ˜๋กœ ์ฐธ์กฐํ•˜๋Š” ์ƒํ™ฉ์„ ๋Œ€๋น„ํ•ด์ค๋‹ˆ๋‹ค.

    ๊ทธ๋Ÿผ ์šฐ์„  Strongํ•˜๊ฒŒ ์„ ์–ธํ•ด๋„ ๋ฌธ์ œ๊ฐ€ ๋˜์ง€ ์•Š๋Š” ์ƒํ™ฉ์„ ๊ฐ€์ •ํ•ด๋ณผ๊นŒ์š”?


    ViewController๊ฐ€ ์žˆ์Œ

    ViewController๊ฐ€ Strongํ•˜๊ฒŒ someView๋ฅผ ์†Œ์œ 

    IB์—์„œ SomeView๊ฐ€ Label์„ SubView๋กœ Strongํ•˜๊ฒŒ ์†Œ์œ 

    ViewController๊ฐ€ ์œ„์˜ Label์„ ์†Œ์œ 


    ์œ„ ์ƒํ™ฉ์˜ retain count๋ฅผ ๊ณ„์‚ฐํ•ด๋ณด๋ฉด


    someView: 1

    Label: 2


    ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์ด ์ƒํ™ฉ์—์„œ ViewController๊ฐ€ dealloc ๋œ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ someView์˜ retain count๋Š” ์ด๊ฒƒ์„ ์ฐธ์กฐํ•˜๋˜ View Controller๊ฐ€ ์‚ฌ๋ผ์ ธ -1์ด ๋˜์–ด 0์ด ๋ฉ๋‹ˆ๋‹ค. ๋˜ Label ์—ญ์‹œ ViewController์˜ ์ฐธ์กฐ๊ฐ€ ์‚ฌ๋ผ์ ธ -1์ด ๋˜๊ณ , ์—ฌ๊ธฐ์— SomeView์˜ ์ฐธ์กฐ ์—ญ์‹œ ์‚ฌ๋ผ์ง€๋ฏ€๋กœ -2๊ฐ€ ๋˜์–ด 0์ด ๋ฉ๋‹ˆ๋‹ค. Strongํ•ด๋„ ์ „ํ˜€ ๋ฌธ์ œ๊ฐ€ ์—†๋Š” ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค.

    ๋งŒ์•ฝ ๋ณต์žกํ•œ View Hierarchy์—์„œ ํŠน์ • subView๊ฐ€ ๋‹ค๋ฅธ subView2๋ฅผ ๊ฐ€์งˆ ๋•Œ subView๊ฐ€ ์˜๋„์น˜ ์•Š๊ฒŒ ํ•ด์ œ๋  ๊ฒฝ์šฐ subView2๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์‚ฌ๋ผ์ง€๊ฒŒ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ๋Š” Strongํ•œ ์„ ์–ธ์ด ํ•„์š”ํ•˜์ฃ .

    ๊ทธ๋Ÿผ ํ•ญ์ƒ Strong์„ ์‚ฌ์šฉํ•ด๋„ ๊ดœ์ฐฎ์„๊นŒ์š”? ๋‹น์—ฐํžˆ ์•„๋‹™๋‹ˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑ์˜ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•˜๋ฉด ViewController์˜ ๋ฉ”์†Œ๋“œ์ธ didReceiveMemoryWarning์ด ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ didReceiveMemoryWarning์—์„œ mainView๋ฅผ nil๋กœ ์ฒ˜๋ฆฌํ•ด์„œ mainView์— ํฌํ•จ๋œ ๋ชจ๋“  Sub View๋“ค์„ deallocํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ™•๋ณดํ•˜๋Š” ๊ฒƒ์ด์ฃ .

    ์ด ๊ฒฝ์šฐ์— ๋งŒ์•ฝ IBOutlet์ด Strongํ•œ Subview๋“ค์„ ๊ฐ–๊ณ  ์žˆ๋‹ค๋ฉด ๊ทธ SubView๋“ค์˜ Reference Count๊ฐ€ 1 ์ดํ•˜๋กœ ์ ˆ๋Œ€ ๋‚ด๋ ค๊ฐ€์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ฆ‰ SuperView๊ฐ€ nil์ด ๋˜๋„ SubView๋Š” dealloc๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ๋ทฐ๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์— ์ƒ์ฃผํ•˜๊ฒŒ ๋˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.


    ๐Ÿง outlet ์—†์ด UI element๋ฅผ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์„๊นŒ?

    ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค! ๊ท€์ฐฎ๊ธด ํ•˜์ง€๋งŒ viewWithTag(_:)๋ผ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ๊ตฌํ˜„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.


๐Ÿง— View Controller Hierarchy(๊ณ„์ธต ๊ตฌ์กฐ)


  • view controller๋Š” tree์™€ ๊ฐ™์€ ๊ตฌ์กฐ์˜ ๊ณ„์ธต์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค. ๋ชจ๋“  iOS ์•ฑ๋“ค์€ main window๊ฐ€ ์žˆ๊ณ , ๋ชจ๋“  window๋Š” root view controller๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค. ์ด view controller๊ฐ€ app window์˜ ์ตœ์ดˆ ํ™”๋ฉด์ด ๋ฉ๋‹ˆ๋‹ค. ํ•˜๋‚˜์˜ ์•ฑ์€ ํ•˜๋‚˜ ์ด์ƒ์˜ window๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Window ๊ทธ ์ž์ฒด๋Š” ์‹œ๊ฐ์ ์ธ ์š”์†Œ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์—†๊ณ , view controller์˜ view๊ฐ€ app์˜ UI ์š”์†Œ๋“ค์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

    AppDelegate์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

    class AppDelegate: UIResponder, UIApplicationDelegate 
    {
        var window:UIWindow?
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
        {
            let mainViewController = MainViewController()
            mainViewController.title = "Main"
    
            let frame = UIScreen.main.bounds
            window = UIWindow(frame: frame)
    
            window!.rootViewController = mainViewController
            window!.makeKeyAndVisible()
    
            return true
        }
    }

    ์œ„์˜ ์ฝ”๋“œ๋Š” app์˜ ์‹œ์ž‘์ ์ด ๋ฉ๋‹ˆ๋‹ค. ์ด ์‹œ์ž‘์ ์—์„œ ์ตœ์ดˆ์˜ ViewController ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  UIWindow ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ๊ทธ ์œˆ๋„์šฐ์— view controller ๊ฐ์ฒด๋ฅผ ๋ถ€์—ฌํ•˜๊ณ  makeKeyAndVisible ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ํ•ด๋‹น View๋ฅผ ๋ณด์—ฌ์ฃผ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

    ๐Ÿง Storyboard๋กœ UI๋ฅผ ๊ทธ๋ฆด ๋•Œ ํ•œ๋ฒˆ๋„ ์ด๋Ÿฐ ์ž‘์—…์„ ํ•ด์ค€ ์ ์ด ์—†๋Š”๋ฐ?!

    ์šฐ๋ฆฌ๋Š” ์‚ฌ์‹ค ์ด ์ž‘์—…์„ Storyboard์—์„œ ํ™”๋ฉด์„ ๋งŒ๋“ค ๋•Œ๋งˆ๋‹ค ํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. "Is Initial View Controller" ์„ ํƒ์„ ํ•˜๋ฉด ์ž๋™์œผ๋กœ ์œ„์˜ ๋กœ์ง์„ ์‹คํ–‰์‹œ์ผœ ์ค๋‹ˆ๋‹ค.

    ๋Œ€๋ถ€๋ถ„์˜ ์•ฑ๋“ค์€ UITabBarController, UINavigationController, UISplitViewController, UIPageViewController์™€ ๊ฐ™์€ "container view controller" ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ view controller๋“ค์€ ๋งŽ์€ view controller๋“ค์„ ๊ด€๋ฆฌ๊ฐ€๋Šฅํ•œ ์ธํ„ฐํŽ˜์ด์Šค์™€ ์š”์†Œ๋กœ์„œ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.


๐Ÿ‘จ๐Ÿผโ€โš•๏ธ View Controller Life Cycle


  • ์ด๋ฒˆ์—” View Controller์˜ Life Cycle์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. App์˜ Life Cycle์ด ์•„๋‹Œ View์˜ Life Cycle์ž…๋‹ˆ๋‹ค!



    view controller์˜ ์ƒ๋ช…์€ ๋‹น์—ฐํžˆ ์ดˆ๊ธฐํ™” ์‹œ์ ์— ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค. view controller ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋˜๋ฉฐ view์˜ ํ”„๋กœํผํ‹ฐ์ธ content view๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค(์•ž์„œ ์–ธ๊ธ‰ํ•œ storyboard๋‚˜ XIB์˜ ํ˜•ํƒœ). ์ด๋ ‡๊ฒŒ view๊นŒ์ง€ ์ƒ์„ฑ๋˜๊ณ  ๋‚˜๋ฉด viewDidLoad ๋ฉ”์†Œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

    ์ผ๋ฐ˜์ ์œผ๋กœ ์ด viewDidLoad๋ฉ”์†Œ๋“œ๋Š” ์ตœ์ดˆ ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด viewDidLoad๋Š” ์• ์ดˆ์— UIViewController์— ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์šฐ๋ฆฌ๊ฐ€ ๊ตฌํ˜„ํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋Š” override function์ด ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” view controller๋Š” ์ด UIViewController๋ฅผ ์ƒ์†ํ•˜๊ฒŒ ๋˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

    ์ด ์‹œ์ ์—์„œ outlet๋“ค์€ ๊ฐ’์„ ๊ฐ€์ ธ์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋ฐ˜์ ์œผ๋กœ viewDidLoad๋Š” view๋ฅผ ๊ตฌํ˜„ํ•  ๋•Œ ์ตœ์ดˆ์˜ ํฌ์ธํŠธ๊ฐ€ ๋˜๊ณ  ์ด ๊ณณ์— ๊ธฐ๋ณธ์ ์ธ ๊ฐ’๋“ค์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.


    ๐Ÿง view controller ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋˜๋ฉด ๋ฐ”๋กœ viewDidLoad๊ฐ€ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์ธ๊ฐ€?

    ๊ฒฐ๋ก ๋ถ€ํ„ฐ ๋งํ•˜์ž๋ฉด ์•„๋‹™๋‹ˆ๋‹ค. view controller์˜ ์ดˆ๊ธฐํ™” ์ฆ‰์‹œ ๋ฉ”์†Œ๋“œ๊ฐ€ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ lazyํ•˜๊ฒŒ ์„ ์–ธ๋˜์–ด view property์— ์ฒ˜์Œ ์ ‘๊ทผ์ด ์ผ์–ด๋‚ฌ์„ ๊ฒฝ์šฐ ๋ฉ”์†Œ๋“œ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.


    ์ด๋ ‡๊ฒŒ viewDidLoad๊ฐ€ ์‹คํ–‰๋˜๊ณ  ๋‚˜๋ฉด view controller๋Š” Appear/Disappear์˜ ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ์‹œ์ ์— ๋”ฐ๋ผ will/Did์˜ ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ‘œ๋กœ ๋‚˜ํƒ€๋‚ด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.


    Will Did
    Appear viewWillAppear(_:) viewDidAppear(_:)
    Disappear viewWillDisappear(_:) viewDidDisappear(_:)

    ์œ„์˜ ๊ทธ๋ฆผ๊ณผ ํ‘œ๋ฅผ ๋น„๊ตํ•ด๋ณด๋ฉด ์ˆœ์„œ๋ฅผ ์ดํ•ดํ•˜๊ธฐ ๋” ํŽธํ•ฉ๋‹ˆ๋‹ค. ๋‹น์—ฐํžˆ view๊ฐ€ ๋‚˜ํƒ€๋‚˜๊ธฐ ์ „์— viewWillAppear๊ฐ€ ๋™์ž‘ํ•˜๊ณ , ๋‚˜ํƒ€๋‚˜๋ฉด viewDidAppear๊ฐ€ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด์ œ view๊ฐ€ ์‚ฌ๋ผ์ง€๊ฒŒ ๋˜๋ฉด viewWillDisappear๊ฐ€ ํ˜ธ์ถœ๋˜๊ณ  ์‚ฌ๋ผ์ง€๋ฉด viewDidDisappear๊ฐ€ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค. ๋„ค์ด๋ฐ์˜ ์ค‘์š”์„ฑ์„ ์ƒˆ์‚ผ ๋Š๋ผ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค :)


    ๊ฐ ๋ฉ”์†Œ๋“œ๋“ค์€ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ animated of type Bool์„ ๊ฐ–๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ฆ‰ view์˜ ์ƒ๋ช…(?)๋ณ€ํ™”๊ฐ€ ์ผ์–ด๋‚  ๋•Œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ๋ฅผ ์ค„ ๊ฒƒ์ธ์ง€์— ๋Œ€ํ•œ ์˜ต์…˜์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ, ๋‹จ์ˆœํžˆ override๋œ ๋ฉ”์†Œ๋“œ๋งŒ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์ƒ์œ„ ํด๋ž˜์Šค(UIViewController)์— ์ด๋ฏธ ์„ ์–ธ๋˜์–ด์žˆ๋Š” ๋ฉ”์†Œ๋“œ, ์ฆ‰ super.method()๋ฅผ ๋จผ์ € ํ˜ธ์ถœํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.


    ๐Ÿš“ ์ด๋Ÿฌํ•œ lifecycle function๋“ค์€ view๊ฐ€ ๋ˆˆ์—์„œ ์‚ฌ๋ผ์งˆ ๋•Œ ์ž‘๋™ํ•œ๋‹ค?

    ์ผ๋ฐ˜์ ์œผ๋กœ ํ•˜๊ธฐ ์‰ฌ์šด ์˜คํ•ด๋กœ ์—„๋ฐ€ํžˆ ์ •์˜ํ•˜๋ฉด ์‚ฌ์‹ค์ด ์•„๋‹™๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฉ”์†Œ๋“œ๋“ค์€ ๊ธฐ๋ณธ์ ์œผ๋กœ view controller์˜ content view๊ฐ€ view hierarchy์—์„œ ์ถ”๊ฐ€๋˜๊ฑฐ๋‚˜ ์‚ฌ๋ผ์ง์„ ๊ธฐ์ค€์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.


    ์œ„์˜ ์ž๋ฃŒ๋“ค์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ฐ ๋ฉ”์†Œ๋“œ์— ์ž‘์„ฑํ•ด์•ผํ•  ๋‚ด์šฉ๋“ค์„ ์ •๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


    viewDidLoad: view controller์˜ ์ง„์ž… ํฌ์ธํŠธ

    viewWillAppear: viewController์˜ content view๊ฐ€ view hierarchy์— ์ถ”๊ฐ€๋˜๊ธฐ ์ „ ๋™์ž‘. viewController๊ฐ€ ํ™”๋ฉด์— ๋ณด์ด๊ธฐ ์ง์ „ ์ผ์–ด๋‚˜์•ผํ•˜๋Š” ๋‹จ์ˆœ ์—ฐ์‚ฐ

    viewDidAppear: viewController์˜ content view๊ฐ€ view hierarchy์— ์ถ”๊ฐ€๋œ ํ›„ ๋™์ž‘. ํ™”๋ฉด์ด ๋‚˜ํƒ€๋‚จ๊ณผ ๋™์‹œ์— ์‹œ์ž‘๋˜์•ผํ•  ์—ฐ์‚ฐ(e.g. ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ)

    viewWillDisappear: viewController์˜ content view๊ฐ€ view hierarchy์— ์‚ญ์ œ๋˜๊ธฐ ์ „ ๋™์ž‘. ํ‚ค๋ณด๋“œ๋ฅผ ์ˆจ๊ธฐ๊ฑฐ๋‚˜ ํŠน์ • ์ž‘์—…์„ ์ €์žฅํ•˜๋Š” ๋“ฑ ํ™”๋ฉด์ด ์‚ฌ๋ผ์ง€๊ธฐ ์ „ ๋™์ž‘ํ•ด์•ผํ•  ์ž‘์—…

    viewDidDisappear: viewController์˜ content view๊ฐ€ view hierarchy์— ์‚ญ์ œ๋œ ํ›„ ๋™์ž‘. ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌ๋œ ์ถ”ํ›„ ์žฌ์ƒ์„ฑ ๊ฐ€๋Šฅํ•œ ๋ฐ์ดํ„ฐ ์ œ๊ฑฐ ๋“ฑ ๋งˆ๋ฌด๋ฆฌ ์ž‘์—…


    ์œ„์˜ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์˜ˆ์‹œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


    viewDidLoad: on-screen messageLabel์— ํ‘œํ˜„๋  ๋ฌธ์ž ํ”„๋กœํผํ‹ฐ ์„ธํŒ…

    viewWillAppear: ๋ฐฑ์—”๋“œ์—์„œ ๋ณ€๊ฒฝ๋œ ์ƒˆ๋กœ์šด UI ์ •๋ณด ์—…๋ฐ์ดํŠธ

    viewDidAppear: ๋กœ๊ทธ์ธ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ณ  LoginViewController ๋„์šฐ๊ธฐ

    viewWillDisappear: ๋ณ€๊ฒฝ์‚ฌํ•ญ db ์ €์žฅ

    viewDidDisappear: ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ(tear down view controller)


Reference: https://learnappmaking.com/view-controller-uiviewcontroller-ios-swift/

๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๋ฐ˜์‘ํ˜•
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
TAG more
ยซ   2025/02   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
๊ธ€ ๋ณด๊ด€ํ•จ