App Life Cycle
์์ ๋ถํฐ ํฌ์คํ ํ๋ คํ๋ App Life Cycle ์ ๋๋ค. ViewController Life Cycle๋ ํ ๋ฒ์ ์ ๋ฆฌํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
์ฐ์ App
์ ํฌ๊ฒ 3๊ฐ์ง ์ํ
๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.Not Running
, Foreground
, Background
์
๋๋ค.
๊ทธ๋ฆฌ๊ณ Foreground๋ ๋ค์ InActive
, Active
Background๋ Suspend
, Running
์ด๋ ๊ฒ ๋๋ ์ ์์ต๋๋ค.
Foreground์ Background์ ๊ณตํต์ ์ ์ฑ์ด ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ผ๊ฐ ์๋ค
์
๋๋ค.
Foreground = ์ฑ์ด ํ๋ฉด์ ์ ์ ์ค์ธ ๊ฒ์ด๊ณ , ๊ทธ ์ค ์ฌ์ฉ์๊ฐ Full Control์ด ๋ถ๊ฐ๋ฅํ๋ค๋ฉด InActive ์ํ์.
์ฆ ์ ํ๋ธ๋ฅผ ๋ณด๋ค๊ฐ ๊ฐ์๊ธฐ ์ ํ๊ฐ ์ค๋ ๊ฒฝ์ฐ ์ ํ๋ธ๋ Active -> InActive -> Background
์ด๋ฐ์์ผ๋ก ์์ง์
๋๋ค.
๋ฌด์กฐ๊ฑด InActive๋ฅผ ๊ฑฐ์นฉ๋๋ค! ์์ฃผ ์ ๊น๋์์ด์. ๋์์ฌ ๋๋ Background -> InActive -> Active
์ด๋ฐ์์
๋๋ค.
Backgorund = ํ๋ฉด์์๋ ๋ด๋ ค๊ฐ์ง๋ง ๋ฉ๋ชจ๋ฆฌ์์๋ ์ํ
์
๋๋ค.
- Suspend (๊ฐ๋งํ ๊ธฐ๋ค๋ฆผ)
- Running (๋ฐฑ๊ทธ๋ผ์ด๋์์ ๋ฌ๋ํ๋ ๊ฒฝ์ฐ, ์ด๋ฉ์ผ ์ ์ก, ์ ๋ก๋, ํ์ด๋จธ ๋ฑ)
๊ทธ๋ฆฌ๊ณ ๋ฐฑ๊ทธ๋ผ์ด๋ ์ํ์์ ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋ถ์กฑํ๋ฉด iOS์ ์ํด Not Running์ผ๋ก ๋ด๋ ค๊ฐ๊ฒ ๋ฉ๋๋ค.
ViewController Life Cycle
ViewController๋ฅผ ๋ง๋ค๋ฉด viewDidLoad์ด๋ฐ ํจ์๋ค์ overrideํจ์ ๋ณผ ์ ์์ฃ ?
์ด๋ A sequence of message is sent to vc as it progresses through its lifetime
์ด๋ผ๊ณ ๋ณผ ์ ์์ต๋๋ค.
์ฆ ViewController๋ Life Cycle์ ๊ฐ์ง๊ณ ์์ต๋๋ค.
viewdidload
view๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ๋ก๋ํ๋ ๊ฒ์ ๋๋ค.
์ฐ๋ฆฌ์ outlet์ด set๋์ด ์์ง๋ง ์์ง view์ bounds๋ ์์ง set๋์ง ์์ผ๋ ์ฌ๊ธฐ์ setํ๋๊ฒ์ ์ฃผ์ํ๋ฉด ์ข์ต๋๋ค.
๋ฉ๋ชจ๋ฆฌ ๋ก๋ ์์
์ ๋ฑ ํ ๋ฒ
๋ง ์คํ๋ฉ๋๋ค.
viewWillAppear
๋ฐ๋ณต์ ์ผ๋ก ํธ์ถ๋ฉ๋๋ค. ์ฆ ๋ค๋ฅธ ํ๋ฉด์ผ๋ก modal์ ํ๊ณ ๊ฐ๊ณ ๋ค์ ๋์์ฌ ๋ ์ด ํจ์๊ฐ ํธ์ถ๋ฉ๋๋ค.
viewDidAppear
์ญ์ ๋ฐ๋ณต์ ํธ์ถ๋๋ฉฐ, viewWillAppear ํ์ ํธ์ถ๋ฉ๋๋ค.
์ ๋๋ฉ์ด์ , ํ์ด๋จธ, ๋ฌด์ธ๊ฐ๋ฅผ ๊ด์ฐฐํ๊ธฐ์(GPS position) ์์ฃผ ์ข์ ๊ณณ์ ๋๋ค.
์ฐ๋ฆฌ๋ User Interaction ๋ฅผ blockํ๋ฉด ์๋๊ธฐ ๋๋ฌธ์ ๋ฌด์ธ๊ฐ ์ค๋๊ฑธ๋ฆฌ๋ ์์ (network fetch)๋ฅผ ํ๊ธฐ์๋ ์ข์ต๋๋ค.
viewWillDisappear
๋ณดํต, viewDidAppear์์ ์ค์ ํ๊ฑธ undoํฉ๋๋ค.
์๋ฅผ ๋ค์ด stop timer ๋ฑ์ด ์๊ฒ ๋ค์.
viewDidDisappear
clean up MVC
๊ทธ ์ธ์
Geometry(๋ทฐ์ ๊ฐ๋ก์ธ๋ก ๋ณ๊ฒฝ)
viewWillLayoutSubviews()
, viewDidLayoutSubviews()
๋ฑ์ ํจ์๋ top-level view์ bound๊ฐ ๋ณ๊ฒฝ๋ ๋ ์ด ๋ฉ์ธ์ง(ํจ์)๊ฐ ํธ์ถ๋จ. Autolayout์ ์ค์ ํ๋ฉด, ์ด๊ฑธ ํธ์ถํ ์ผ์ด ๋ฑํ ์์ต๋๋ค.
์ข
์ข
ํธ์ถ๋จ. ์ด๊ฒ ํญ์ view์ bound๊ฐ ๋ณ๊ฒฝ๋๋๊ฑธ ์๋ฏธํ๋๊ฒ ์๋๋ฏ๋ก Don't do anything here that can't be properly done repeatedly.
๋ผ๊ณ ํ๋ค์
Low Memory
didRecieveMemoryWarning()
๊ฐ ํธ์ถ๋ฉ๋๋ค.
awakeFromNib
Waking up from an storyboard
๋ ๋ ํธ์ถ๋ฉ๋๋ค.
๊ทธ ์ธ์๋ viewWillTransition
๋ฑ์ด ์์ต๋๋ค.
๋ค์์๋ App Life Cycle๊ณผ ์ฐ๊ด์ด ์๋ AppDelegate, SceneDelegate์ ๋ํด ํฌ์คํ ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.