ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [iOS] SwiftGen์œผ๋กœ ๋ฆฌ์†Œ์Šค ๊ด€๋ฆฌํ•˜๊ธฐ
    ๐ŸŽ iOS/๊ฐœ๋ฐœ 2023. 6. 4. 13:03

     

    SwiftGen์€ CocoaPods, Homebrew, Mint ๋“ฑ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์„ ํ†ตํ•ด ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ,

    ๋ณธ ๊ธ€์—์„œ๋Š” Homebrew๋กœ ์„ค์น˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

    ํ„ฐ๋ฏธ๋„์—์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    brew update
    brew install swiftgen

     

     

    ์„ค์น˜๋ฅผ ์™„๋ฃŒํ•˜๊ณ  ๋‚˜๋ฉด ๋ฆฌ์†Œ์Šค๋“ค์„ ์ฝ”๋“œ๋กœ ํŒŒ์‹ฑํ•ด์ค„ ์ˆ˜ ์žˆ๋Š” yml ํŒŒ์ผ์ด ํ•„์š”ํ•œ๋ฐ,

    yml ํŒŒ์ผ์€ ํ„ฐ๋ฏธ๋„์—์„œ swiftgen config init ์„ ์ž…๋ ฅํ•ด ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

     

     

     

    ๋˜๋Š” Xcode์—์„œ๋„ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ถ”๊ฐ€ํ•ด yml ํŒŒ์ผ์„ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ๋Š”๋ฐ,

    ์šฐ์„  ํ”„๋กœ์ ํŠธ ํŒŒ์ผ - Targets - Build Phases - [+] New Run Script Phase๋กœ ์Šคํฌ๋ฆฝํŠธ ์„น์…˜์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

     

     

     

     

    ํ„ฐ๋ฏธ๋„์—์„œ ์ž…๋ ฅํ•˜๋Š” ๋ช…๋ น์–ด์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ swiftgen config init์„ ์ž‘์„ฑํ•˜๊ณ  ํ”„๋กœ์ ํŠธ๋ฅผ ๋นŒ๋“œํ•˜๋ฉด

    ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ์— swiftgen.yml ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

     

    ํŒŒ์ผ์„ ์—ด์–ด๋ณด๋ฉด ๋ชจ๋‘ ์ฃผ์„์ฒ˜๋ฆฌ๊ฐ€ ๋˜์–ด์žˆ์„ ํ…๋ฐ

    ํ•„์š”ํ•œ ๋ถ€๋ถ„๋งŒ ์ ์ ˆํžˆ ์ฐพ์•„์„œ ์ฃผ์„์„ ํ•ด์ œํ•˜๊ณ  ํ”„๋กœ์ ํŠธ์— ๋งž๊ฒŒ ์ž‘์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

     

     

     

     

    ํ˜„์žฌ ์ œ ํ”„๋กœ์ ํŠธ์˜ ํด๋”๊ตฌ์กฐ๊ฐ€ ์™ผ์ชฝ๊ณผ ๊ฐ™์€๋ฐ์š”.

    Image Asset๊ณผ Color Asset์„ ๊ตฌ๋ถ„๋œ ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด๋‘์—ˆ๊ณ , Font ํด๋”์—๋„ ํฐํŠธ๋“ค์„ ๋‹ค์ˆ˜ ๋„ฃ์–ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค.

     

    ์ด ๊ตฌ์กฐ์— ๋งž์ถฐ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ์˜ค๋ฅธ์ชฝ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    inputs ์˜์—ญ์— ๋ฆฌ์†Œ์Šค ํŒŒ์ผ์„ ์ž‘์„ฑํ•ด์ฃผ๋Š”๋ฐ, ๋ฆฌ์†Œ์Šค ํŒŒ์ผ์ด yml ํŒŒ์ผ๊ณผ ๊ฐ™์€ ์œ„์น˜์— ์žˆ์ง€ ์•Š์œผ๋‹ˆ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ƒ์„ธํžˆ ์ž‘์„ฑํ•ด์ค๋‹ˆ๋‹ค.

     

    (โš ๏ธ ๊ฒฝ๋กœ ์ƒ์„ธํžˆ ์ ๊ธฐ ๊ท€์ฐฎ๋‹ค๊ณ  yml ํŒŒ์ผ์˜ ์œ„์น˜๋ฅผ ์˜ฎ๊ฒจ ๋นŒ๋“œํ•˜๋ฉด

    Command PhaseScriptExecution failed with a nonzero exit code ์˜ค๋ฅ˜๊ฐ€ ๋‚ฉ๋‹ˆ๋‹ค!

    yml ํŒŒ์ผ ์œ„์น˜๋Š” ๊ฑด๋“œ๋ฆฌ์ง€ ์•Š๊ธฐ โš ๏ธ)

     

    outputs ์˜์—ญ์—๋Š” ์ด ๋ฆฌ์†Œ์Šค๋“ค์„ ๊ด€๋ฆฌํ•  ์ƒˆ๋กœ ์ƒ์„ฑ๋  ํŒŒ์ผ๋ช…์„ ์ง€์ •ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

    ์ž์„ธํ•œ ์˜ต์…˜์€ SwiftGen GitHub์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

     

     

     

    ์ด์ œ ๋‹ค์‹œ Run Script๋กœ ๋Œ์•„์™€์„œ swift config run์œผ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์ž…๋ ฅํ•˜๊ณ  ๋นŒ๋“œํ•ด๋ด…๋‹ˆ๋‹ค.

     

    (๋ฌผ๋ก  ํ„ฐ๋ฏธ๋„์—์„œ ์ง์ ‘ ์ž…๋ ฅํ•ด๋„ ๋˜์ง€๋งŒ, ํ•œ ๋ฒˆ Run Script๋กœ ์ž‘์„ฑํ•ด๋‘๋ฉด

    ๋นŒ๋“œํ• ๋•Œ๋งˆ๋‹ค ํ•ด๋‹น ๋ช…๋ น์–ด๊ฐ€ ์‹คํ–‰๋˜์–ด ์ž๋™์œผ๋กœ outputs ํŒŒ์ผ๋“ค์„ ์—…๋ฐ์ดํŠธํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ํŽธ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.)

     

     

     

    ์ง€์ •ํ•œ ๊ฒฝ๋กœ์— ์ง€์ •ํ•œ ํŒŒ์ผ๋ช…์„ ๊ฐ–๋Š” Asset.swift์™€ Font.swift๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

     

     

     

     

     

    ์•„์ง ํ”„๋กœ์ ํŠธ์—๋Š” ๋‘ ํŒŒ์ผ์ด ์ถ”๊ฐ€๋˜์ง€ ์•Š์•˜์„ ํ…๋ฐ, Add File์„ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ์—๋„ ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

     

     

     

     

    ํŒŒ์ผ์„ ์—ด์–ด๋ณด๋ฉด ์ด๋ ‡๊ฒŒ Enum ํ˜•ํƒœ๋กœ ์ฝ”๋“œ๊ฐ€ ์ž๋™์œผ๋กœ ์ž‘์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค!

    ์ด์ œ ์ด ์ฝ”๋“œ๋ฅผ ์ด์šฉํ•ด ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

     

    let myButton: UIButton = {
        let btn = UIButton()
        btn.imageView.image = Asset.Image.TabBar.homeOn.image // Image Asset ์‚ฌ์šฉ
        btn.titleLabel.textColor = Asset.Color.green100.color // Color Assset ์‚ฌ์šฉ
        btn.titleLabel.font = FontFamily.NotoSansKR.regular.font(size: 14) // Font Asset ์‚ฌ์šฉ
        return btn
    }()

    ์ง ! ์—„์ฒญ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค ๐Ÿ‘

     

     


    ์ฐธ๊ณ 

    https://vapor3965.tistory.com/103

    ๋Œ“๊ธ€

Designed by Tistory.