๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป Programming ๊ฐœ๋ฐœ/๐ŸŽ iOS ๊ฐœ๋ฐœ, Swift

[Swift] ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•œ Cocoapods ์„ค์น˜ ๋ฐ ์„ค์ • + ์„ค์น˜๊ณผ์ •์— ์˜ค๋ฅ˜๊ฐ€ ์ƒ๊ธธ ๊ฒฝ์šฐ

by kimdee 2022. 3. 28.
๋ฐ˜์‘ํ˜•

 

 

 

 

์ถœ์ฒ˜:blog.bitrise.io

 

Cocoapods ์ด๋ž€?

์• ํ”Œ ๊ด€๋ จ ํ”„๋กœ๊ทธ๋žจ(Swift, Objective-C)์„ ์ž‘์„ฑํ•  ๋•Œ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ด€๋ฆฌ๋ฅผ ๋„์™€์ฃผ๋Š” ์˜์กด์„ฑ ๊ด€๋ฆฌ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

https://cocoapods.org/

 

CocoaPods.org

CocoaPods is built with Ruby and is installable with the default Ruby available on macOS. We recommend you use the default ruby. Using the default Ruby install can require you to use sudo when installing gems. Further installation instructions are in the g

cocoapods.org

 

ํ˜„์žฌ 3๋ฐฑ๋งŒ๊ฐœ๊ฐ€ ๋„˜๋Š” ์•ฑ์—์„œ ์‚ฌ์šฉ์ค‘์ธ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

 

์„ค์น˜๋ฐฉ๋ฒ•

์ €๋Š” ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” MacOS์™€ Xcode๊ฐ€ ์ตœ์‹ ๋ฒ„์ „์ด ์•„๋‹ˆ๋ผ์„œ์ธ์ง€ ์„ค์น˜๊ณผ์ •์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒจ์„œ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ณผ์ •์„ ํ†ตํ•ด ์ตœ์ข…์ ์œผ๋กœ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ ์ €๋Š” MacOS Big Sur 11.3.1, Xcode 13.1 ์„ ์‚ฌ์šฉ์ค‘์— ์žˆ์Šต๋‹ˆ๋‹ค.

1.  ํ„ฐ๋ฏธ๋„์—์„œ ์„ค์น˜ํ•˜๊ธฐ 

 

$ sudo gem install cocoapods

 

ํ„ฐ๋ฏธ๋„์—์„œ ์œ„ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ €์˜ ๊ฒฝ์šฐ extconf faild, exit code 1๊ณผ ๊ฐ™์€ ๋ฉ”์‹œ์ง€๊ฐ€ ๋œจ๋ฉด์„œ ์„ค์น˜๋ฅผ ์‹คํŒจํ•˜์˜€๋Š”๋ฐ์š”. 

 

cocoapods ์„ค์น˜ ์‹คํŒจ ํ™”๋ฉด

 

2.  Homebrew์—์„œ ์„ค์น˜ํ•˜๊ธฐ 

Homebrew๋ฅผ ์ด์šฉํ•˜์—ฌ ์„ค์น˜๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ํ•˜์—ฌ  ํ„ฐ๋ฏธ๋„์—์„œ HOMEBREW ์ฐฝ์„ ์ƒˆ๋กœ ์—ด์–ด์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์˜€์Šต๋‹ˆ๋‹ค. 

 

$ brew install cocoapods

 

 

๋งŒ์•ฝ, Homebrew๊ฐ€ ์—†๋‹ค๋ฉด ํ„ฐ๋ฏธ๋„์—์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 

๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜ ๊ณต์‹ํ™ˆํŽ˜์ด์ง€์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

https://brew.sh/

 

Homebrew

The Missing Package Manager for macOS (or Linux).

brew.sh

๊ทธ๋Ÿฌ๋‚˜ ์ €๋Š” Homebrew์—์„œ๋„ ์•„๋ž˜์™€ ๊ฐ™์€ ์„ค์น˜์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

3.  Homebrew์—์„œ ์ด์ „ ๋ฒ„์ „ ๋ช…์‹œํ•˜์—ฌ ์„ค์น˜ 

$ sudo gem install -n /usr/local/bin cocoapods -v 1.8.4

 

-V ๋ฅผ ์ด์šฉํ•˜์—ฌ Cocoapods 1.8.4 ๋ฒ„์ „์„ ์„ค์น˜ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ตœ์‹ ๋ฒ„์ „์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฒ„์ „์„ ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๋ผ๋Š” ์•ˆ๋‚ด๋ฌธ๊ตฌ๊ฐ€ ๋œจ์ง€๋งŒ ๋ฌด์‹œํ•˜๊ณ  ์‚ฌ์šฉํ•ด๋„ ๋ฉ๋‹ˆ๋‹ค. ๋“œ๋””์–ด ์˜ค๋ฅ˜์—†์ด ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. 

 

์•„๋ž˜ ์• ํ”Œ ๊ฐœ๋ฐœ์ž ํฌ๋Ÿผ์˜ ์Šค๋ ˆ๋“œ๋ฅผ ์ฐธ๊ณ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.  

 

https://developer.apple.com/forums/thread/668456

 

Trouble with installing cocoapods | Apple Developer Forums

Same problem - XCode 12.3 on Mac OS 10.15.6. Tried the CocoaPod mac app from the CocoaPods about page, which did have an option to install the command line tool, but it was version 1.1.x for some reason.... Brew install did the trick, and installed 1.10.0.

developer.apple.com

 

4.  ์„ค์น˜์—ฌ๋ถ€ ํ™•์ธ

pod --version

 

์œ„ ๋ช…๋ น์–ด๋ฅผ ํ„ฐ๋ฏธ๋„์—์„œ ์ž…๋ ฅํ•˜์—ฌ ์„ค์น˜์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 

Cocoapods ์‚ฌ์šฉ๋ฐฉ๋ฒ•

 

1.  ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ์—์„œ pod init

 

๋จผ์ € xcode๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“  ํ›„ ์ข…๋ฃŒํ•œ ๋‹ค์Œ, ํ„ฐ๋ฏธ๋„์—์„œ ํ•ด๋‹น ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ๊ฒฝ๋กœ๋กœ ์ด๋™ํ•œ ํ›„ $ pod init ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ํ•ด๋‹น xcode ํ”„๋กœ์ ํŠธ์— Cocoapods๋ฅผ ์„ธํŒ…ํ•ด์ค๋‹ˆ๋‹ค. 

$ cd {ํ”„๋กœ์ ํŠธ๊ฒฝ๋กœ}
$ pod init

 

initialise ๊ฐ€ ์ž˜๋˜๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ํ”„๋กœ์ ํŠธ ํด๋”์— Podfile์ด ์ƒ๊ธด ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ด Podfile ์„ ์ด์šฉํ•˜์—ฌ ์™ธ๋ถ€๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€ํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 

๋˜๋Š”, Podfile ์ด๋ผ๋Š” ์ด๋ฆ„์˜ ํ…์ŠคํŠธํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์•„๋ž˜ ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  ์ด ๋•Œ ํ”Œ๋žซํผ ๋“ฑ์˜ ๋ฒ„์ „์€ ์‚ฌ์šฉํ•˜๊ณ   ์žˆ๋Š” ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ์—  ๋”ฐ๋ผ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
  pod 'AFNetworking', '~> 2.6'
  pod 'ORStackView', '~> 3.0'
  pod 'SwiftyJSON', '~> 2.3'
end

 

2.  Podfile ์ˆ˜์ •ํ•˜๊ธฐ

 use_frameworks!  ์•„๋ž˜์—, ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

pod '๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋ฆ„','๋ฒ„์ „๋ช…'

 

 

์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ณต์‹ํ™ˆํŽ˜์ด์ง€์—์„œ๋„ Cocoapods์—์„œ์˜ ์ด์šฉ๋ฐฉ๋ฒ•์„ ๋ช…์‹œํ•ด๋‘๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ๋„คํŠธ์›Œํฌ ํ†ต์‹ ์— ์‚ฌ์šฉํ•˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์ธ Alamofire ์˜ Cocoapods ์‚ฌ์šฉ๋ฐฉ๋ฒ•์„ ์บก์ณํ•œ ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค. 

 

์ €์˜ ๊ฒฝ์šฐ ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์— Alamofire์™€ Charts ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์œผ๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด Podfile์— ์ €์žฅ ํ›„ ์ข…๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค. 

 

3.  Podfile ์ €์žฅ ํ›„ pod ์„ค์น˜

์•„๊นŒ ์ผœ๋‘” ํ„ฐ๋ฏธ๋„์ฐฝ์—์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

$ pod install

 

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๋œน๋‹ˆ๋‹ค. Downloading Dependencies, Installing {LibraryName} (version) ์„ ๊ฑฐ์ณ, Generating Pods project, Integrating client project๊นŒ์ง€ ๋œจ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 

4.  ์ด์ œ๋ถ€ํ„ฐ๋Š”  xcworkspace๋ฅผ ์ด์šฉํ•˜๊ธฐ

์œ„์˜ pod install์ด ์ œ๋Œ€๋กœ ์™„๋ฃŒ๋˜๋ฉด  ํ•ด๋‹น ํ”„๋กœ์ ํŠธ ํด๋”์— *.xcworkspace๊ฐ€ ์ƒˆ๋กœ ์ƒ์„ฑ๋œ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ๋กœ ์„ค์น˜ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ธฐ์กด์˜ *.xcodeproj ๊ฐ€ ์•„๋‹ˆ๋ผ xcworkspace ํ™•์žฅ์ž๋ฅผ ๊ฐ€์ง„ ํŒŒ์ผ์„ ์‹คํ–‰ํ•ด์•ผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$ open App.xcworkspace

 

*.xcworkspace ๋ฅผ ์—ด๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ Pods ํ”„๋กœ์ ํŠธ๊ฐ€ ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ด์ œ Pods ๋‚ด์—์„œ ๋ชจ๋“  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 


 

๋งˆ์น˜๋ฉฐ 

 

์˜ค๋Š˜๋„ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

 

๊ถ๊ธˆํ•œ ์ ์ด ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€๋กœ, ๋„์›€์ด ๋˜์…จ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

ํ˜น์‹œ ํ”ผ๋“œ๋ฐฑํ•˜์‹ค ๋‚ด์šฉ ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“  ๋Œ“๊ธ€๋กœ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

 

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€