/ios

Primary LanguageSwift

๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป IOS Swift

Swift XCode

โœจ ์ œ๊ฐ€ ์ƒ๊ฐํ•˜๊ธฐ์— ํ•„์š”ํ•˜๊ฑฐ๋‚˜ ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋ถ€๋ถ„๋งŒ ์ •๋ฆฌํ•ด๋†“์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ก ์ƒ์˜ ์ˆœ์„œ์™€ ๋งž์ง€ ์•Š์„ ์ˆ˜ ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด์„œ ๋ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :) โœจ

โœ๏ธ ๋ชฉ์ฐจ

App Delegate

  • App์ด ํ•ด์•ผํ•  ์ผ(background / foreground ์ง„์ž…, ์™ธ๋ถ€์—์„œ์˜ ์š”์ฒญ ๋“ฑ) ์„ ๋Œ€์‹  ๊ตฌํ˜„ํ•จ
  1. ์•ฑ์˜ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋ฅผ ์ดˆ๊ธฐํ™”
  2. ์•ฑ์˜ scene ํ™˜๊ฒฝ์„ค์ •(configuration)
  3. ์•ฑ ๋ฐ–์—์„œ ๋ฐœ์ƒํ•œ ์•Œ๋ฆผ (๋ฐฐํ„ฐ๋ฆฌ ๋ถ€์กฑ, ๋‹ค์šด๋กœ๋“œ ์™„๋ฃŒ)์— ๋Œ€์‘
  4. ํŠน์ •ํ•œ scenes, views, view controllers์— ํ•œ์ •๋˜์ง€ ์•Š๊ณ  ์•ฑ ์ž์ฒด๋ฅผ ํƒ€๊ฒŸ์œผ๋กœ ํ•˜๋Š” ์ด๋ฒคํŠธ์— ๋Œ€์‘
  5. ์• ํ”Œ ํ‘ธ์‰ฌ ์•Œ๋žŒ ์„œ๋น„์Šค์™€ ๊ฐ™์ด ์‹คํ–‰ ์‹œ ์š”๊ตฌ๋˜๋Š” ๋ชจ๋“  ์„œ๋น„์Šค๋ฅผ ๋“ฑ๋ก
  • UIApplicationMain: entry point์™€ ์•ฑ์˜ ์ž…๋ ฅ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•˜๋Š” run loop ์ƒ์„ฑ (์ด์— ๋Œ€ํ•œ ์‘๋‹ต์œผ๋กœ ์‹œ์Šคํ…œ์€ ์‘์šฉํ”„๋กœ๊ทธ๋žจ ๊ฐ์ฒด(app์˜ lifecycle ๋‹ด๋‹น)๋ฅผ ์ƒ์„ฑ -> ์‹œ์Šคํ…œ์—์„œ ์•ฑ์„ ์‹คํ–‰)

  • UIApplicationDelegate: ์•ฑ์„ ์„ธํŒ…ํ•˜๊ณ , ์•ฑ ์ƒํƒœ ๋ณ€ํ™”์— ์‘๋‹ตํ•˜๋ฉฐ, ๋‹ค๋ฅธ app-level ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์ •์˜ํ•œ ๋ฉ”์†Œ๋“œ์˜ set

    • var window: UIWindow?: ์•ฑ์˜ window์— ๋Œ€ํ•œ ์ฐธ์กฐ๋ฅผ ์ €์žฅ. ์•ฑ์˜ view ๊ณ„์ธต๊ตฌ์กฐ์˜ ๋ฃจํŠธ๋ฅผ ๋‚˜ํƒ€๋ƒ„.
      • window๋Š” optional property์ž„ (UIWindow?์ด๊ธฐ์—)
  • UIResponder: ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์‘๋‹ต ๋“ฑ๊ณผ ๊ฐ™์€ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์ถ”์ƒ ์ธํ„ฐํŽ˜์ด์Šค.

    • ์ด๋ฒคํŠธ์˜ ํ๋ฆ„

      ์Šคํฌ๋ฆฐ์ƒท 2020-07-03 ์˜คํ›„ 5 55 13
      1. ์ด๋ฒคํŠธ(๋ฒ„ํŠผ ํด๋ฆญ ๋“ฑ)๋ฅผ UIEvent๋กœ ๋ณ€ํ™˜ํ•ด์„œ ์‹คํ–‰ ์ค‘์ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐ์ฒด์ธ UIApplication์˜ sendEvent ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

      2. UIApplication์˜ sendEvent ๋ฉ”์„œ๋“œ๋Š” UIWindow์—๊ฒŒ sendEvent๋ฅผ ๋‹ค์‹œ ๋ณด๋‚ธ๋‹ค.

      3. UIWindow๋Š” ์ด๋ฒคํŠธ์— ํ•ด๋‹นํ•˜๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ž์‹ ๋ทฐ ์ค‘์—์„œ ์ตœ์ดˆ ์‘๋‹ต ๊ฐ์ฒด์— ๋ณด๋‚ธ๋‹ค.

      4. ์ตœ์ดˆ ์‘๋‹ต ๊ฐ์ฒด๊ฐ€ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ , ์ด๋ฒคํŠธ๋Š” ์†Œ๋ฉธ๋œ๋‹ค.

โ€‹

  • Scene Session์ด ์ƒ์„ฑ๋˜๊ฑฐ๋‚˜ ์‚ญ์ œ๋  ๋•Œ AppDelegate์— ์•Œ๋ฆฌ๋Š” ๋ฉ”์†Œ๋“œ ์ถ”๊ฐ€. (Scene session์€ ์•ฑ์—์„œ ์ƒ์„ฑํ•œ ๋ชจ๋“  scene์˜ ์ •๋ณด๋ฅผ ๊ด€๋ฆฌ)
// ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ตœ์ดˆ ์‹คํ–‰๋˜๋Š” ์ง€์ 
application: UIApplication, didFinishLaunchingWithOptions

// ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๊ฐ€์ ธ์˜จ ์ดˆ๊ธฐ configuration data(๊ตฌ์„ฑ ๋ฐ์ดํ„ฐ)๋ฅผ ๋กœ๋“œํ•ด์ฃผ๋Š” ์ง€์  (์ƒˆ๋กœ์šด scene session์ด ์ƒ์„ฑ๋˜์—ˆ์„ ๋•Œ ํ˜ธ์ถœ)
application: UIApplication, configurationForConnecting

// ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์™„์ „ํžˆ ์ข…๋ฃŒ๋˜๊ธฐ ์ „ ์‹œ์  (user๊ฐ€ Scene์„ ๋‹ซ์„ ๋•Œ ํ˜ธ์ถœ)
application: UIApplication, didDiscardSceneSessions

Scene Delegate

: UI ์ƒํƒœ๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋Š” UILifeCycle์— ๋Œ€ํ•œ ์—ญํ• ์„ ํ•จ.

  • Scene: UI์˜ ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” windows์™€ view controllers๊ฐ€ ๋“ค์–ด์žˆ์Œ. ๊ฐ scene์— ํ•ด๋‹นํ•˜๋Š” UIWindowSceneDelegate ๊ฐ์ฒด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ.

    • appDelegate์—์„œ scene session์„ ํ†ตํ•ด scene์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์—…๋ฐ์ดํŠธ ๋ฐ›์Œ.
  • Scene Session: scene์˜ ๊ณ ์œ ํ•œ ๋Ÿฐํƒ€์ž„ ์ธ์Šคํ„ด์Šค ๊ด€๋ฆฌ.

  • UIWindowSceneDelegate: UIKit์™€ ์•ฑ ๊ฐ„์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ์กฐ์ •ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ

  • UIResponder: ์œ„์˜ ๋‚ด์šฉ๊ณผ ๋™์ผ

// scene์˜ ์—ฐ๊ฒฐ์ด ํ•ด์ œ๋  ๋•Œ ํ˜ธ์ถœ
sceneDidDisconnect(_:)

// scene๊ณผ ์ƒํ˜ธ์ž‘์šฉ์ด ์‹œ์ž‘๋  ๋•Œ ํ˜ธ์ถœ
sceneDidBecomeActive(_:)

// ์‚ฌ์šฉ์ž๊ฐ€ scene๊ณผ ์ƒํ˜ธ์ž‘์šฉ์„ ์ค‘์ง€ํ•  ๋•Œ ํ˜ธ์ถœ ex) ๋‹ค๋ฅธ ํ™”๋ฉด์œผ๋กœ ์ „ํ™˜ํ•  ๋•Œ
sceneWillResignActive(_:)

// scene์ด ํฌ๊ทธ๋ผ์šด๋“œ๋กœ ์ง„์ž…ํ•  ๋•Œ ํ˜ธ์ถœ
sceneDidEnteForeground(_:)

// scene์ด ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์ง„์ž…ํ•  ๋•Œ ํ˜ธ์ถœ
sceneDidBackground(_:)

์Šคํฌ๋ฆฐ์ƒท 2020-07-03 ์˜คํ›„ 5 55 34

View Controller

: ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ธํ„ฐํŽ˜์ด์Šค์™€ ์ธํ„ฐํŽ˜์ด์Šค์™€ ๋ฐ์ดํ„ฐ ๊ฐ„์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ๊ด€๋ฆฌ

  • UIViewController: view์˜ ์†์„ฑ๊ณผ ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜
    • content view controllers: ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‚ด์šฉ์„ ๊ด€๋ฆฌ
    • Container view controllers: ๋‹ค๋ฅธ view controller์— ์žˆ๋Š” ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•œ ๋’ค ํšจ์œจ์ ์ธ ๋ฐฉํ–ฅ ์ œ์‹œ

์Šคํฌ๋ฆฐ์ƒท 2020-07-04 ์˜คํ›„ 9 58 37

UIVIewController Lifecycle

  • init: View Controller๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๋Š” ๋ฉ”์†Œ๋“œ
  • viewDidLoad: view๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œ๋œ ๋’ค ์‹คํ–‰ํ•˜๋Š” ๋ฉ”์†Œ๋“œ
  • viewWillAppear: view๋ฅผ ์‚ฌ์šฉ์ž์˜ ์Šคํฌ๋ฆฐ์— ๋„์šฐ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์†Œ๋“œ ex) scrollํ• ๋•Œ ๋‚˜ํƒ€๋‚˜๋Š” ์ •๋ณด
  • viewDidAppear: view๋ฅผ ์‚ฌ์šฉ์ž์˜ ์Šคํฌ๋ฆฐ์— ๋„์šด ๋’ค ์‹คํ–‰ํ•˜๋Š” ๋ฉ”์†Œ๋“œ + ์• ๋‹ˆ๋ฉ”์ด์…˜์˜ ์‹œ์ž‘์„ ์ •์˜
  • viewWillDisappear: view๊ฐ€ ์‚ฌ์šฉ์ž์˜ ์Šคํฌ๋ฆฐ์— ๊บผ์ง€๊ธฐ ์ง์ „ ์‹คํ–‰๋˜๋Š” ๋ฉ”์†Œ๋“œ. Ex) ์ž„์˜์˜ ํ…์ŠคํŠธ๋ฅผ ๋ฐ”๊พธ๋ฉด ์ง์ „์˜ ํ…์ŠคํŠธ๋ฅผ ์ €์žฅํ•ด์ฃผ๋Š” ์—ญํ• ?
  • viewDidDisappear: ์Šคํฌ๋ฆฐ์ด ์™„์ „ํžˆ ๊บผ์กŒ์„ ๋•Œ ์‹คํ–‰๋˜๋Š” ๋ฉ”์†Œ๋“œ

์Šคํฌ๋ฆฐ์ƒท 2020-07-04 ์˜คํ›„ 11 00 32

Constraints

  • leading space: ์ „์ฒดํ™”๋ฉด๊ณผ component์˜ ์™ผ์ชฝ ๋์˜ ๊ฑฐ๋ฆฌ๋ฅผ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ (์™ผ์ชฝ ๋งˆ์ง„๊ณผ ๋น„์Šท)

  • Trailing space: ์ „์ฒดํ™”๋ฉด๊ณผ component์˜ ์˜ค๋ฅธ์ชฝ ๋์˜ ๊ฑฐ๋ฆฌ๋ฅผ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ(์˜ค๋ฅธ์ชฝ ๋งˆ์ง„๊ณผ ๋น„์Šท)

  • center vertically in container: y์ถ•์„ ๊ธฐ์ค€์œผ๋กœ component์˜ ์œ„์น˜๋ฅผ ๊ฐ€์šด๋ฐ๋กœ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ.

  • center horizontally in container: x์ถ•์„ ๊ธฐ์ค€์œผ๋กœ component์˜ ์œ„์น˜๋ฅผ ๊ฐ€์šด๋ฐ๋กœ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ

  • horizontal spacing: ๋‘๊ฐœ์˜ component์˜ ์‚ฌ์ด์˜ spacing์„ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ

  • Equal width: component์˜ ๊ธธ์ด๋ฅผ ๋™์ผํ•˜๊ฒŒ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ. (๋™์ผํ•œ ๊ธธ์ด๋ฅผ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ์ง€ ๊ฒฝ๊ณ ์ฐฝ์ด ๋œจ์ง€ ์•Š์Œ.)

  • Aspect ratio: width์™€ height์˜ ๋น„์œจ์„ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ

  • Top: ์ง€๋ชฉ๋œ component์˜ ์œ„์ชฝ spacing์„ ์ง€๋ชฉํ•œ component์™€ ๊ฐ™๊ฒŒ ์ง€์ •.

  • Bottom: ์ง€๋ชฉ๋œ component์˜ ์•„๋ž˜์ชฝ spacing์„ ์ง€๋ชฉํ•œ component์™€ ๊ฐ™๊ฒŒ ์ง€์ •.

๋””์ž์ธ ํŒจํ„ด

๋””์ž์ธ ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ : ๊ฐ๊ฐ์˜ ์—ญํ• ์„ ๋‚˜๋ˆ  ์ฝ”๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, ์œ ์ง€๋ณด์ˆ˜์™€ ๊ฐœ๋ฐœ ํšจ์œจ์ด ์ข‹์•„์ง

MVC (Model + View + Controller)

- MVC์˜ ๊ตฌ์กฐ

  • Model: ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฐ์ดํ„ฐ์™€ ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„
  • View: ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง€๋Š” UI๋ถ€๋ถ„
  • Controller: ์‚ฌ์šฉ์ž์˜ ์•ก์…˜์„ ๋ฐ›๊ณ  ์ฒ˜๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„

์Šคํฌ๋ฆฐ์ƒท 2020-07-03 ์˜คํ›„ 5 55 57

- MVC์˜ ๋™์ž‘์ˆœ์„œ

  1. controller๊ฐ€ ์‚ฌ์šฉ์ž์˜ action์„ ๋ฐ›์Œ

  2. ์‚ฌ์šฉ์ž์˜ action์„ ํ™•์ธํ•œ controller๋Š” model์„ ์—…๋ฐ์ดํŠธ ์‹œํ‚ด

    • View๊ฐ€ Model์„ ์ด์šฉํ•˜์—ฌ ์ง์ ‘ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋ฐฉ๋ฒ•
    • Model์—์„œ View์—๊ฒŒ Notifyํ•˜์—ฌ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๋ฐฉ๋ฒ•
    • View๊ฐ€ Polling์„ ํ†ตํ•ด ์ฃผ๊ธฐ์ ์œผ๋กœ Model์˜ ๋ณ€๊ฒฝ์„ ๊ฐ์ง€ํ•˜์—ฌ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๋ฐฉ๋ฒ•
  3. controller๋Š” Model์„ ๋‚˜ํƒ€๋‚ด์ค„ View๋ฅผ ์„ ํƒ

  4. View๋Š” Model์„ ์ด์šฉํ•˜์—ฌ ํ™”๋ฉด์„ ๋‚˜ํƒ€๋ƒ„

- MVC์˜ ํŠน์ง•

  • controller๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ view๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Œ
  • controller๋Š” view๋ฅผ ์„ ํƒํ•  ๋ฟ์ด์ง€ ์ง์ ‘ ์—…๋ฐ์ดํŠธ๋ฅผ ํ•˜์ง€ ์•Š์Œ (view๋Š” controller๋ฅผ ์•Œ์ง€ ๋ชปํ•˜๋Š” ํ˜•ํƒœ)

- MVC์˜ ์žฅ์ 

  • ๋‹จ์ˆœํ•œ ๊ตฌ์กฐ -> ๋ณดํŽธ์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ๋””์ž์ธ ํŒจํ„ด

- MVC์˜ ๋‹จ์ 

  • view์™€ model ์‚ฌ์ด์˜ ์˜์กด์„ฑ์ด ๋†’์Œ.

    • ๋†’์€ ์˜์กด์„ฑ์€ ์–ดํ”„๋ฆฌ์ผ€์ด์…˜์˜ ๊ทœ๋ชจ๊ฐ€ ์ฆ๊ฐ€ํ•˜๋ฉด ๋ณต์žกํ•˜๊ณ , ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Œ.
  • model๋งŒ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅ

MVP (Model + View + Presenter)

- MVP์˜ ๊ตฌ์กฐ

  • Model: ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฐ์ดํ„ฐ์™€ ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„
  • View: ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง€๋Š” UI๋ถ€๋ถ„
  • Presenterr: View์—์„œ ์š”์ฒญํ•œ ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ model์„ ๊ฐ€๊ณตํ•˜์—ฌ view์— ์ „๋‹ฌํ•ด์ฃผ๋Š” ๋ถ€๋ถ„

์Šคํฌ๋ฆฐ์ƒท 2020-07-03 ์˜คํ›„ 6 26 34

- MVP์˜ ๋™์ž‘

  1. View๊ฐ€ ์‚ฌ์šฉ์ž์˜ Action์„ ๋ฐ›์Œ
  2. view๋Š” ๋ฐ์ดํ„ฐ๋ฅผ presentor์— ์š”์ฒญ
  3. presenter๋Š” model์—๊ฒŒ ๋ฐ์ดํ„ฐ ์š”์ฒญ
  4. model์€ presentor์—์„œ ์š”์ฒญ๋ฐ›์€ ๋ฐ์ดํ„ฐ์— response.
  5. presenter๊ฐ€ view์—๊ฒŒ ์‘๋‹ต๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†ก
  6. view๋Š” presentor๊ฐ€ ์ „์†กํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ™”๋ฉด์„ ๊ตฌ์„ฑํ•จ.

- MVP์˜ ํŠน์ง•

  • Presenter๋Š” view์™€ model์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ์—, ๋‘˜์„ ์—ฐ๊ฒฐ์‹œํ‚ค๋Š” ์ ‘์ฐฉ์ œ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•จ
  • presentor์™€ view๋Š” 1:1 ๊ด€๊ณ„์ด๋‹ค.

- MVP์˜ ์žฅ์ 

  • view์™€ model ์‚ฌ์ด์˜ ์˜์กด์„ฑ์ด ์กด์žฌํ•˜์ง€ ์•Š์Œ.
    • view์™€ model์€ presentor๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์—.

- MVP์˜ ๋‹จ์ 

  • view์™€ presentor์˜ ์˜์กด์„ฑ์ด ์กด์žฌํ•˜์—ฌ, ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ทœ๋ชจ๊ฐ€ ์ปค์งˆ์ˆ˜๋ก ๋‘˜์‚ฌ์ด์˜ ์˜์กด์„ฑ์ด ๊ฐ•ํ•ด์ง

MVVM (Model + View + View Model)

- MVVM์˜ ๊ตฌ์กฐ

  • Model: ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฐ์ดํ„ฐ์™€ ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„ (๋ฐ์ดํ„ฐ์˜ ํ‹€)
  • View: ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง€๋Š” UI๋ถ€๋ถ„
  • View Model: View๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋งŒ๋“  View๋ฅผ ์œ„ํ•œ Model. View๋ฅผ ๋‚˜ํƒ€๋‚ด์ฃผ๊ธฐ ์œ„ํ•œ Model์ด์ž View๋“ค์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•œ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„. (๋ฐ์ดํ„ฐ ์ €์žฅ ๋ถ€๋ถ„)

์Šคํฌ๋ฆฐ์ƒท 2020-07-03 ์˜คํ›„ 6 33 13

- MVVM์˜ ์ž‘๋™ ๋ฐฉ์‹

  1. View๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž์˜ action์ด ๋“ค์–ด์˜ด
  2. view์— action์ด ๋“ค์–ด์˜ค๋ฉด, command ํŒจํ„ด์œผ๋กœ view model์— action์„ ์ „๋‹ฌ
  3. view model์€ model์—๊ฒŒ ๋ฐ์ดํ„ฐ ์š”์ฒญ
  4. model์€ ์š”์ฒญ๋ฐ›์€ ๋ฐ์ดํ„ฐ๋ฅผ view model์— ์ „๋‹ฌ
  5. view model์€ ์‘๋‹ต๋ฐ›์€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€๊ณตํ•˜์—ฌ ์ €์žฅ
  6. View๋Š” view model๊ณผ data binding์„ ํ•˜๋ฉฐ ํ™”๋ฉด์„ ๋‚˜ํƒ€๋ƒ„

- ๋ฐ์ดํ„ฐ ๋ฐ”์ธ๋”ฉ: ํ™”๋ฉด์— ๋ณด์ด๋Š” ๋ฐ์ดํ„ฐ์™€ ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ผ์น˜์‹œํ‚ค๋Š” ๊ธฐ๋ฒ•

- command ํŒจํ„ด: ์‹คํ–‰๋  ๊ธฐ๋Šฅ์„ ์บก์Šํ™”ํ•จ์œผ๋กœ์จ ์ฃผ์–ด์ง„ ์—ฌ๋Ÿฌ ๊ธฐ๋Šฅ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์žฌ์‚ฌ์šฉ์„ฑ์ด ๋†’์€ ํด๋ž˜์Šค๋ฅผ ์„ค๊ณ„ํ•˜๋Š” ํŒจํ„ด

- MVVM์˜ ํŠน์ง•

  • command ํŒจํ„ด๊ณผ data binding ๋‘๊ฐ€์ง€ ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„
  • command ํŒจํ„ด๊ณผ data binding์„ ์ด์šฉํ•˜์—ฌ view์™€ view model ์‚ฌ์ด์˜ ์˜์กด์„ฑ์„ ์—†์•ฐ
  • view model๊ณผ view๋Š” 1:n ๊ด€๊ณ„์ž„

- MVVM์˜ ์žฅ์ 

  • view์™€ model ์‚ฌ์ด / view์™€ view model ์‚ฌ์ด์˜ ์˜์กด์„ฑ์ด ์—†์Œ.
  • ๊ฐ ๋ถ€๋ถ„์˜ ๋…๋ฆฝ์„ฑ์œผ๋กœ ์ธํ•ด ๋ชจ๋“ˆํ™”ํ•˜์—ฌ ๊ฐœ๋ฐœ ๊ฐ€๋Šฅ

- MVVM์˜ ๋‹จ์ 

  • view model ์„ค๊ณ„๊ฐ€ ์–ด๋ ค์›€

VIPER

- VIPER์˜ ๊ตฌ์กฐ

  • View: ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง€๋Š” UI๋ถ€๋ถ„ / user interaction์„ ๋ฐ›๋Š” ์—ญํ• 
  • interactor: presentor๋กœ ๋ถ€ํ„ฐ ๋ฐ›์€ ๋ชจ๋ธ ๋ณ€๊ฒฝ์‚ฌํ•ญ์— ๋”ฐ๋ผ entity์— ์ ‘์†ํ•˜์—ฌ entity๋กœ๋ถ€ํ„ฐ ์ˆ˜์‹ ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ Presenter๋กœ ์ „๋‹ฌํ•˜๋Š” ๋ถ€๋ถ„
  • presenter: view์™€ interactor์˜ ์ค‘๊ฐ„๋‹ค๋ฆฌ ์—ญํ• . view์— ๋Œ€ํ•œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง
  • entity: ๋„คํŠธ์›Œํฌ, DB๋“ฑ์˜ ๋ฐ์ดํ„ฐ ๋ชจ๋ธ
  • Router: VIPER ์ปดํฌ๋„ŒํŠธ๋“ค์˜ dependency injection์„ ๋‹ด๋‹น. (์˜์กด์„ฑ์„ ๋‚ฎ์ถค) / ํ™”๋ฉด๊ฐ„์˜ ํƒ์ƒ‰์„ ์œ„ํ•œ ๋ผ์šฐํŒ… ๋‹ด๋‹น(์–ด๋–ป๊ฒŒ ํ™”๋ฉด ์ „ํ™˜์ด ๋  ๊ฒƒ์ธ์ง€๋ฅผ ๊ด€๋ฆฌํ•จ.)

์Šคํฌ๋ฆฐ์ƒท 2020-07-03 ์˜คํ›„ 9 25 34

- VIPER์˜ ์ž‘๋™ ์›๋ฆฌ

  1. view์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด presenter๊ฐ€ ํ•ด๋‹น action์„ ์ „๋‹ฌ
  2. presenter๋กœ ๋ฐ›์€ ๋ชจ๋ธ์— ๋”ฐ๋ผ์„œ interactor์˜ entity์— ์ ‘์†ํ•˜์—ฌ entity๋กœ ๋ถ€ํ„ฐ ์ˆ˜์‹ ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ presenter๋กœ ์ „๋‹ฌ.
  3. presentor๋Š” interactor๋กœ ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ ์˜ค๊ณ , view์— ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋ƒ„.

- VIPER์˜ ํŠน์ง•

  • ํ…Œ์ŠคํŠธ๊ฐ€ ์šฉ์ดํ•˜๋‹ค.

  • ์–‘๋ฐฉํ–ฅ ๋กœ์ง ์ˆœํ™˜

- VIPER์˜ ์žฅ์ 

  • MVP / MVVM / MVC ์˜ ๊ตฌ์กฐ ์‚ฌ์ด์—์„œ ์ œ์ผ ๋ถ„๋ฐฐ๊ฐ€ ์ž˜ ๋˜์–ด์žˆ๋Š” ๊ตฌ์กฐ์ž„.

- VIPER์˜ ๋‹จ์ 

  • ์ฝ”๋“œ์–‘์ด ๊ฐ€์žฅ ๋งŽ๋‹ค.
  • ์ž‘์€ ๊ธฐ๋Šฅ์—๋„ ๋งŽ์€ ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•ด์•ผํ•จ
  • ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๋‹ค

VIP (Clean Swift)

- VIP ๊ตฌ์กฐ

  • view: ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง€๋Š” UI๋ถ€๋ถ„

  • Controller: view๋ฅผ ์ฝ”๋“œ์— ๋ฐ”์ธ๋”ฉํ•˜๋Š” ๋ ˆ์ด์–ด

  • Interactor: controller์˜ ์š”์ฒญ์„ ๋ณด๋‚ด์•ผํ•˜๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ๊ณ„์ธต

  • presenter: interactor๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ํ˜•ํƒœ๋ฅผ view์— ๋งž๊ฒŒ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๊ฒŒ controller์—๊ฒŒ ์ „๋‹ฌ

  • Router: controller์—์„œ ๋ฐœ์ƒํ•œ ์ด๋ฒคํŠธ๋ฅผ ๋‹ค๋ฅธ user case์— ์ „๋‹ฌํ•˜๋Š” ์—ญํ• 

์Šคํฌ๋ฆฐ์ƒท 2020-07-03 ์˜คํ›„ 9 26 08

- VIP ์ž‘๋™ ์›๋ฆฌ

  1. view๊ฐ€ ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
  2. controller์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ๋ชจ๋ธ์„ ์š”์ฒญ ํ›„ interactor ํ˜ธ์ถœ
  3. interactor์—์„œ๋Š” ๊ธฐ๋ณธ ์ฝ”์–ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์—‘์„ธ์Šค
  4. interactor์—์„œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์ฒ˜๋ฆฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์‹œ presenter์— ๋ณด๋ƒ„
  5. Presenter์—์„œ interactor์—์„œ ๋ฐ›์€ ๊ฒฐ๊ณผ์— ๋Œ€ํ•œ UI์ฒ˜๋ฆฌ๋ฅผ controller์— ์ „๋‹ฌํ•˜์—ฌ view์— ๋ณด์—ฌ์คŒ.

- VIP์˜ ํŠน์ง•

  • ๋‹จ๋ฐฉํ–ฅ cycle๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ์Œ. ( interactor -> presenter -> view controller -> interaction)
  • presentor๋Š” interactor๊ณผ ์ง์ ‘์ ์œผ๋กœ ์†Œํ†ต ๋ถˆ๊ฐ€
  • ํด๋ž˜์Šค ์˜์กด์„ฑ์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋‚˜์˜จ ๊ตฌ์กฐ (๋ชจ๋“ˆ ์˜์กด์„ฑ๋ณด๋‹ค ํด๋ž˜์Šค ์˜์กด์„ฑ์„ ์ค‘์ ์œผ๋กœ ๋‘๊ณ  ๋งŒ๋“ฆ. )

- VIP์˜ ์žฅ์ 

  • ์•ก์…˜์— ๋Œ€ํ•œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ presenter๋ฅผ ํ†ตํ•˜์ง€ ์•Š๊ณ  ๋ฐ”๋กœ interactor์— ์š”์ฒญํ•ด์„œ ๋ณ€ํ™”๋ฅผ ์ฃผ๋ฉฐ ๋‹จ๋ฐฉํ–ฅ์œผ๋กœ ํ”Œ๋กœ์šฐ ์ง„ํ–‰
  • ํ™•์žฅ์„ฑ์ด ์ข‹์Œ
  • ๋ชจ๋“  layer๊ฐ€ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์กด์žฌํ•˜๊ธฐ์—, ํ…Œ์ŠคํŠธ์— ์šฉ์ด

- VIP์˜ ๋‹จ์ 

  • layer๋ผ๋ฆฌ ์ „๋‹ฌํ• ๋•Œ request / response ๋ชจ๋ธ์„ ๋žฉํ•‘ํ•ด์•ผํ•˜๋Š” ๋ถˆํŽธํ•จ์ด ์กด์žฌ
  • ๋ชจ๋ธ์„ ๋žฉํ•‘ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ, ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๊ฒฐํ•ฉ๋  ์ˆ˜ ์žˆ์Œ
  • ๋น„๋™๊ธฐ ์•ก์…˜์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๊ฐ€ ๋ณ„๋„๋กœ ํ•„์š”ํ•จ

Collection View

  • Items: ์Šคํฌ๋ฆฐ์— ๋””์Šคํ”Œ๋ ˆ์ด ํ•˜๊ณ  ์‹ถ์€ ๊ฐ๊ฐ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋‚˜ํƒ€๋ƒ„ ex) ์‚ฌ์ง„
  • Groups: ์—ฌ๋Ÿฌ๊ฐœ์˜ item์„ ๊ฐ€์ง€๊ณ  ์žˆ์Œ. ์–ด๋””์— ๋ ˆ์ด์•„์›ƒ ์œ„์น˜ํ•ด์•ผํ•˜๋Š”์ง€๋ฅผ ๋‚˜ํƒ€๋ƒ„
  • Sections: data๋ฅผ ๋ฌถ์–ด๋†“์€ ๊ฒƒ. datasource์—์„œ ์–ด๋–ป๊ฒŒ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ตฌ์„ฑ๋˜์–ด์žˆ๋Š”์ง€๋ฅผ ์•Œ๋ ค์ฃผ๋Š” ์—ญํ• .

Collection View์˜ ๊ตฌ์„ฑ์š”์†Œ

์Šคํฌ๋ฆฐ์ƒท 2020-07-04 ์˜คํ›„ 10 33 19

UICollectionViewDataSource

: ๋ฐ์ดํ„ฐ์™€ collection view๊ฐ€ ์š”๊ตฌํ•˜๋Š” view๋ฅผ ์ œ๊ณต

  • ์–ผ๋งˆ๋‚˜ ๋งŽ์€ section์ด collection view์— ๋“ค์–ด๊ฐˆ ๊ฒƒ์ธ์ง€
  • ์ฃผ์–ด์ง„ section์—์„œ ์–ผ๋งˆ๋‚˜ ๋งŽ์€ item์ด section์•ˆ์— ์‚ฝ์ž…๋  ๊ฒƒ์ธ์ง€
  • ์ฃผ์–ด์ง„ section๊ณผ item์—์„œ, ์ƒ์‘ํ•˜๋Š” ๋‚ด์šฉ์ด ๋ณด์—ฌ์ง€๊ธฐ ์œ„ํ•ด ์–ด๋– ํ•œ view๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š”์ง€

UICollectionViewDelegate

  • collection view ๋‚ด๋ถ€์—์„œ ์„ ํƒํ•˜๊ฑฐ๋‚˜ ์ค‘์š”ํ•œ item์„ ๊ด€๋ฆฌ
  • item์— ๋Œ€ํ•œ ํ–‰๋™์„ ์ˆ˜ํ–‰

UICollectionViewDelegateFlowLayout

  • item์˜ ์‚ฌ์ด์ฆˆ๋ฅผ ์ •์˜
  • grid์™€ item ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๋ฅผ ์ •์˜

Segue

: ์Šคํ† ๋ฆฌ๋ณด๋“œ์—์„œ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ ์‚ฌ์ด์˜ ํ™”๋ฉด์ „ํ™˜์„ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ๊ฐ์ฒด

Segue ์ž‘๋™๋ฒ•

  1. ์„ธ๊ทธ์›จ์ด ์‹๋ณ„์ž๋ฅผ ๊ฐ€์ ธ์˜จ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ํ•ด๋‹น ๋ทฐ๊ฐ€ ๋งž๋Š”์ง€(identifier๊ฐ€ ๊ฐ™์€์ง€) ๋น„๊ต
  2. ๋งž์œผ๋ฉด ๋ชฉ์ ์ง€ ๋ทฐ๋กœ ์บ์ŠคํŒ….
    • ์ด๋•Œ, ๋ชฉ์ ์ง€ ๋ทฐ๋ฅผ ์„ค์ •ํ•œ ๋’ค, ๋ชฉ์ ์ง€ ๋ทฐ์— ์ „๋‹ฌ๋ฐ›์•„์•ผ ํ•˜๋Š” ๋ณ€์ˆ˜๋ฅผ ์ฐธ์กฐํ•˜์—ฌ ์ด๋™ํ•  ๊ฐ’์„ ํ• ๋‹น.

Animation

UIKit์˜ ์• ๋‹ˆ๋ฉ”์ด์…˜ API

// ๊ธฐ๋ณธ ํƒ€์ด๋ฐ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋กœ๋“œ
animate(withDuration: animations:)

// ์™„๋ฃŒ ํ•ธ๋“ค๋Ÿฌ ์ถ”๊ฐ€
animate(withDuration: animations: completion: )

//๋”œ๋ ˆ์ด ๋ฐ ๋‹ค๋ฅธ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์˜ต์…˜ ์‚ฌ์šฉ
animate(withDuration: delay: options: animations: completion: )

// ์ผ๋ฐ˜์ ์ธ ๊ณก์„  ํƒ€์ด๋ฐ ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ์Šคํ”„๋ง์— ์˜ํ•œ ํƒ€์ด๋ฐ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ดํŒ…ํ•˜๋Š” ํ•จ์ˆ˜
animate(withDuration: delay: usingSpringWithDamping: initialSpringVelocity: options: animations: completion: )

// ํ‚ค ํ”„๋ ˆ์ž„ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํ‘œ์‹œ
animateKeyframes(withDuration: delay: options: animations: completion:)

// ๋ทฐ ํŠธ๋žœ์ง€์…˜
transition(with: duration: options: animations: completion: )

// ์ œ 3์˜ ๋ทฐ๋ฅผ ํŠธ๋ Œ์ง€์…˜
transition(_: on: options: animations: completion: )

CGAffineTransform

: ๋ทฐ์˜ ํ”„๋ ˆ์ž„์„ ๊ณ„์‚ฐํ•˜์ง€ ์•Š๊ณ  2D ๊ทธ๋ž˜ํ”ฝ์„ ๊ทธ๋ฆฌ๋Š” ๋ฐฉ๋ฒ•

  • Scale: ๋ทฐ์˜ ๋„“์ด์™€ ๋†’์ด๋ฅผ ๋ฐฐ๋กœ ์ฆ๊ฐ€์‹œํ‚ค๋Š” ์—ญํ• 
  • Rotate: ๋ทฐ๋ฅผ ํšŒ์ „
  • Translate: ๋ทฐ์˜ ์œ„์น˜๋ฅผ ๋ณ€๊ฒฝ
CGAffineTransform(translationX: view.bounds.width, y:0).scaledBy(x: 3, y:3).rotated(by: 180)
// view.bounds.width๋งŒํผ x์ถ•์œผ๋กœ ์ด๋™ํ•˜๊ณ , x์™€ y๋ฅผ 3๋ฐฐ๋กœ ๋Š˜๋ฆฐ ํ›„ 180๋„ ํšŒ์ „

๐Ÿ“ Reference List