ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Bundle - Foundation
    iOS/๐ŸŽ Documentation 2021. 1. 25. 00:05
    ์ฐธ๊ณ  ์ž๋ฃŒ : developer.apple.com/documentation/foundation/bundle

     

    ์ฐพ์•„๋ณด๊ฒŒ ๋œ ์ด์œ 

    Apple ์—์„œ ์ œ๊ณตํ•˜๋Š” Food Tracker ์•ฑ์„ ๊ตฌํ˜„ํ•˜๋Š” ๋„์ค‘ @IBDesignable ์„ ์‚ฌ์šฉํ•˜์—ฌ custom control์„ Interface Builder๊ฐ€ ์‹คํ–‰ํ•  ์ˆ˜์žˆ๊ฒŒ ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

     

    ๊ทธ๋Ÿฐ๋ฐ Asset Catalog ์— ์ €์žฅํ•œ ์ด๋ฏธ์ง€๋ฅผ Interface Builder๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋ ค๋ฉด Catalog์˜ ๋ฒˆ๋“ค์„ ๋ช…์‹œ์ ์œผ๋กœ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

     

    ๊ทธ๋ž˜์„œ UIImage(named:) ๋Œ€์‹  UIImage(named:in:compatibleWith:) ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์—ฌ๊ธฐ์„œ Bundle ์˜ ๊ฐœ๋…์„ ๋ชฐ๋ผ์„œ ์ •๋ฆฌํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

     

    Overview

     

    ๋””์Šคํฌ ๋‚ด์˜ Bundle directory ์— ์ €์žฅ๋œ ์ฝ”๋“œ์™€ ์ž์›๋“ค์— ๋Œ€ํ•œ ํ‘œํ˜„๋ฐฉ์‹ ์ž…๋‹ˆ๋‹ค.

     

    ์• ํ”Œ์€ ์•ฑ, ํ”„๋ ˆ์ž„์›Œํฌ, ํ”Œ๋Ÿฌ๊ทธ์ธ ๋“ฑ์„ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ Bundle ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

     

    Bundle ์€ ์ž์‹ ์ด ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ์ž์›๋“ค์„ ์ž˜ ์ •์˜๋œ ์„œ๋ธŒ ๋””๋ ‰ํ† ๋ฆฌ์— ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

     

    ๊ทธ๋ฆฌ๊ณ  Bundle ์˜ ๊ตฌ์กฐ๋Š” Bundle ์˜ ํƒ€์ž…์ด๋‚˜ ํ”Œ๋žซํผ์— ๋”ฐ๋ผ ๋‹ค์–‘ํ•ฉ๋‹ˆ๋‹ค.

     

    Bundle ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•จ์œผ๋กœ์„œ, ์–ด๋–ค Bundle์˜ ๊ตฌ์กฐ๋ฅผ ๋ชฐ๋ผ๋„ ๊ทธ Bundle์˜ ์ž์›์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๋ฒˆ๋“ค์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๊ฐ€ ๋˜๊ฒ ๋„ค์š”!

     

    Bundle ์˜ค๋ธŒ์ ํŠธ๋Š” ์•„์ดํ…œ์˜ ์œ„์น˜๋ฅผ ์•Œ์•„๋‚ด๊ณ , Bundle ์˜ ๊ตฌ์กฐ, ์‚ฌ์šฉ์ž ์„ค์ •, localization ๊ทธ๋ฆฌ๊ณ  ๋‹ค๋ฅธ ๊ด€๋ จ๋œ ์š”์†Œ๋“ค์„ ์•Œ์•„๋‚ด๋Š”๋ฐ ๋‹จ ํ•˜๋‚˜์˜ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

     

    ์–ด๋– ํ•œ ์‹คํ–‰ ํŒŒ์ผ ์ด๋“  Bundle ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•ฑ Bundle ๋‚ด๋ถ€ ํ˜น์€ ๋‹ค๋ฅธ ๊ณณ์— ์œ„์น˜ํ•œ ์•Œ๋ ค์ง„ Bundle ์— ์žˆ๋Š” ์ž์›์˜ ์œ„์น˜๋ฅผ ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ์ปจํ…Œ์ด๋„ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ๋‚˜ ํŒŒ์ผ์‹œ์Šคํ…œ์˜ ๋‹ค๋ฅธ ๋ถ€๋ถ„์— ์žˆ๋Š” ํŒŒ์ผ๋“ค์„ ์ฐพ๋Š”๋ฐ์—๋Š” Bundle ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    ์ปจํ…Œ์ด๋„ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ๋ฌด์—‡์„ ๋งํ•˜๋Š”์ง€ ์•„์ง ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค..

     

    Bundle ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ผ๋ฐ˜์ ์ธ ํŒจํ„ด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

     

    1. ์˜๋„ํ•œ Bundle ๋””๋ ‰ํ„ฐ๋ฆฌ ์˜ Bundle ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ

     Food Tracker ์—์„œ๋Š” Bundle.main ์œผ๋กœ ์•ฑ ๋ฒˆ๋“ค ์ธ์Šคํ„ด์Šค๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค.

     

    2. ํ•„์š”ํ•œ ์ž์›์˜ ์œ„์น˜๋ฅผ ์ฐพ๊ฑฐ๋‚˜ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ์œ„ํ•˜์—ฌ Bundle ์˜ค๋ธŒ์ ํŠธ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ

     

    3. ์ž์›๊ณผ ์ƒํ˜ธ์ž‘์šฉํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ๋‹ค๋ฅธ ์‹œ์Šคํ…œ API ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ

    Food Tracker์—์„œ๋Š” UIImage(named:in:compatibleWith:) ์˜ in ํŒŒ๋ผ๋ฏธํ„ฐ์— Bundle์„ ๋„ฃ์—ˆ์Šต๋‹ˆ๋‹ค.

     

    ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ๋ช‡๋ช‡ ์ž์›๋“ค์€ Bundle ์„ ํ†ตํ•˜์ง€ ์•Š๊ณ  ์œ„์น˜๋ฅผ ์ฐพ์•„๋‚ด๊ฑฐ๋‚˜ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ์˜ˆ๋ฅผ ๋“ค์–ด ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ, ์šฐ๋ฆฌ๋Š” Asset catalog ์— ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•˜๊ณ  UIImage(named:) ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.

    FoodTracker์—์„œ๋Š” @IBDesinable์„ ์‚ฌ์šฉํ•œ custom control ์„ Interface builder ๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

     

    ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ฌธ์ž์—ด ์ž์›์„ ๋ถˆ๋Ÿฌ์˜ฌ๋•Œ, .string ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋Œ€์‹ ์— NSLocalizedString ์„ ์‚ฌ์šฉํ•ด ๊ฐœ๋ณ„ ๋ฌธ์ž์—ด์„ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.


     

    Finding and Opening a Bundle

     

    ์ž์›์ด ์–ด๋””์žˆ๋Š”์ง€ ์ฐพ๊ธฐ ์ „์—, ์šฐ๋ฆฌ๋Š” ๋จผ์ € ์–ด๋–ค Bundle์ด ์ž์›์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”์ง€ ๋ฐ˜๋“œ์‹œ ๋ช…์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

     

    Bundle ํด๋ž˜์Šค๋Š” ๋งŽ์€ ์ƒ์„ฑ์ž๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€๋งŒ, ๊ฐ€์žฅ ์ž์ฃผ ์ž์šฉํ•˜๋Š” ๊ฒƒ์€ Bundle.main ์ž…๋‹ˆ๋‹ค.

     

    Main Bundle ์€ ํ˜„์žฌ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” Bundle ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

     

    ๊ทธ๋ž˜์„œ ์–ด๋–ค ์•ฑ์˜ Main bundle ์˜ค๋ธŒ์ ํŠธ๋Š” ์•ฑ๊ณผ ํ•จ๊ป˜ ๋”ธ๋ ค์˜ค๋Š” ์ž์›๋“ค์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

     

     ๋งŒ์•ฝ ์šฐ๋ฆฌ์˜ ์•ฑ์ด ํ”Œ๋Ÿฌ๊ทธ์ธ์ด๋‚˜ ํ”„๋ ˆ์ž„์›Œํฌ ํ˜น์€ ๋‹ค๋ฅธ ๋ฒˆ๋“ค ์ฝ˜ํ…์ธ ์™€ ์ƒํ˜ธ์ž‘์šฉํ•œ๋‹ค๋ฉด, Bundle ํด๋ž˜์Šค์˜ ๋‹ค๋ฅธ ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ์šฐ๋ฆฌ๋Š” ํ•ญ์ƒ ์•Œ๋ ค์ง„ URL ์ด๋‚˜ ๊ฒฝ๋กœ๋ฅผ ํ†ตํ•ด์„œ Bundle ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ๋Š” ์šฐ๋ฆฌ๊ฐ€ ์ด๋ฏธ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” Bundle์— ์‰ฝ๊ฒŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.

     

    ์˜ˆ๋ฅผ ๋“ค์–ด ๋งŒ์•ฝ ์šฐ๋ฆฌ์˜ ์•ฑ์„ ํ”„๋ ˆ์ž„์›Œํฌ์™€ ์—ฐ๊ฒฐํ•  ๋•Œ, ์šฐ๋ฆฌ๋Š” ๊ทธ ํ”„๋ ˆ์ž„์›Œํฌ์— ์ •์˜๋œ ํด๋ž˜์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœํ•œ ํ”„๋ ˆ์ž„ ์›Œํฌ ๋ฒˆ๋“ค์„ ์ฐพ๊ธฐ ์œ„ํ•ด init(for:) ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    // Get the app's main bundle
    let mainBundle = Bundle.main
    
    // ํ˜น์€
    let mainBundle = Bundle(for: type(of: self))
    
    // Get the bundle containing the specified private class.
    let myBundle = Bundle(for: NSClassFromString("MyPrivateClass")!)

     

    Locating Resources in a Bundle

     

    ์šฐ๋ฆฌ๋Š” Bundle ์•ˆ์— ์žˆ๋Š” ํŠน์ • ์ž์›์˜ ์œ„์น˜๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด Bundle ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

     

    ์ž์›์„ ์ฐพ์„๋•Œ, ์šฐ๋ฆฌ๋Š” ์ž์›์˜ ์ด๋ฆ„๊ณผ ์ž์›์˜ ํƒ€์ž…์„ ์ตœ์†Œํ•œ์œผ๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

     

    ํŠน์ • ์„œ๋ธŒ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์žˆ๋Š” ์ž์›์˜ ๊ฒฝ์šฐ, ์šฐ๋ฆฌ๋Š” ๊ทธ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋˜ํ•œ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ์ž์›์˜ ์œ„์น˜๋ฅผ ์ฐพ์€ ํ›„์—๋Š”, ๋ฒˆ๋“ค ๋ฃจํ‹ด์ด ์šฐ๋ฆฌ๊ฐ€ ํŒŒ์ผ์„ ์—ด ์ˆ˜ ์žˆ๋„๋ก๊ฒฝ๋กœ ๋ฌธ์ž์—ด์ด๋‚˜ URL ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

     

    Bundle ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ์ž์›์„ ์ฐพ๋Š” ํŒจํ„ด์ด ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ํ•ญ์ƒ ์–ธ์–ด์— ์ข…์†์ ์ด์ง€ ์•Š์€ Global resources ๋จผ์ € ์ฐพ์•„์„œ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

    ์–ธ์–ด๊ฐ€ ์ •ํ•ด์ ธ์žˆ๋Š” ์ž์›์€ .lproj  ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์œ„์น˜ํ•ฉ๋‹ˆ๋‹ค.

     

    ์„ฑ๋Šฅ์ƒ์˜ ์ด์œ ๋กœ Global ์™€ Localized ๊ฐ€ ์กด์žฌํ•œ๋‹ค๋ฉด ํ•ญ์ƒ Global ์„ ๋ฐ˜ํ™˜ํ•˜๋ฏ€๋กœ, ๊ฐ™์€ ์ž์›์— ๋Œ€ํ•ด ๋‘ ๊ฐ€์ง€ ๋ฒ„์ „์„ ๋™์‹œ์— ๋‘๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

     

     

     

    ๋!


     

    ๋‹ค์Œ ๊ธ€: 

    'iOS > ๐ŸŽ Documentation' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

    Application Bundles - Bundle Structures  (0) 2021.01.26
    Cocoa (Touch) ๋ž€  (0) 2021.01.25
    Hashable - Protocol  (0) 2021.01.20
    [iOS] Equatable ์ด๋ž€?  (0) 2021.01.20
    The Role of View Controllers (3) - Overview - View Controller Programming Guide for iOS  (0) 2021.01.14

    ๋Œ“๊ธ€

์–ด์ œ๋ณด๋‹ค ๋ฐœ์ „ํ•œ ๋‚˜