๐Ÿ“ฑ App Development Study/iOS๐ŸŽ

[Udemy iOS & Swift Bootcamp] 3rd Party Libraries & Cocoapods

ibelieveinme 2023. 6. 18. 17:44
728x90

*3rd Party Libraryies: ์™ธ๋ถ€ ์˜คํ”ˆ์†Œ์Šค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค

*Cocoapods: Xcode ์—์„œ Library๋“ค์„ ๊ด€๋ฆฌํ•˜๋Š” ๋„๊ตฌ. Cocoapods์— 95,000๊ฐœ ์ด์ƒ์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์กด์žฌํ•œ๋‹ค.


Xcode ์—์„œ๋Š” ๋‹ค์–‘ํ•œ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ Cocoapods ๋„๊ตฌ๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค.

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‚˜์—ดํ•œ ํ›„ pod install ๊ตฌ๋ฌธ์œผ๋กœ ์ž๋™์„ค์น˜ํ•ด์ฃผ๊ณ , pod update ๊ตฌ๋ฌธ์„ ํ†ตํ•ด ์ž๋™์œผ๋กœ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์—…๋ฐ์ดํŠธํ•ด์ฃผ๋Š” ๋“ฑ ๊ด€๋ฆฌ๊ฐ€ ์šฉ์ดํ•˜๋‹ค.

 

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

๊ฒ€์ƒ‰์ฐฝ์— ์›ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฒ€์ƒ‰ํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

1. Cocoapods ์„ค์น˜ํ•˜๊ธฐ

$ sudo gem install cocoapods

ํ„ฐ๋ฏธ๋„์„ ํ‚ค๊ณ  ์œ„ ๊ตฌ๋ฌธ์„ ์ž…๋ ฅํ•œ๋‹ค.

 

1-1) ๋งŒ์•ฝ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ์„ค์น˜ํ•˜์ง€ ์•Š์œผ๋ฉด homebrew๋กœ ์„ค์น˜ํ•ด๋ณด์ž.

 

Homebrew

The Missing Package Manager for macOS (or Linux).

brew.sh

 

homebrew ์„ค์น˜๋ฅผ ์œ„ํ•ด ํ„ฐ๋ฏธ๋„์— ์œ„ ๊ตฌ๋ฌธ์„ ์ž…๋ ฅํ•œ๋‹ค.

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

 

homebrew๋ฅผ ํ†ตํ•ด cocoapods ๋ฅผ ์„ค์น˜ํ•˜์ž.

$ brew cleanup -d -v
$ brew install cocoapods

 

๋‚˜๋Š” homebrew๋กœ ์„ค์น˜ํ–ˆ๋Š”๋ฐ๋„ ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋‚˜์™€์„œ ์—๋Ÿฌ์—์„œ ํ•˜๋ผ๋Š” ๋Œ€๋กœ ์ˆœ์„œ๋Œ€๋กœ ํ–ˆ๋”๋‹ˆ ์ •์ƒ์„ค์น˜๋˜์—ˆ๋‹ค.

$ brew install cocoapods
==> Downloading https://formulae.brew.sh/api/formula.jws.json
##################################################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
##################################################################################################### 100.0%
Warning: Treating cocoapods as a formula. For the cask, use homebrew/cask/cocoapods
Warning: cocoapods 1.12.1 is already installed, it's just not linked.
To link this version, run:
  brew link cocoapods
$ brew link cocoapods
Linking /usr/local/Cellar/cocoapods/1.12.1... 
Error: Could not symlink bin/xcodeproj
Target /usr/local/bin/xcodeproj
already exists. You may want to remove it:
  rm '/usr/local/bin/xcodeproj'


To force the link and overwrite all conflicting files:
  brew link --overwrite cocoapods


To list all files that would be deleted:
  brew link --overwrite --dry-run cocoapods
$ brew link --overwrite cocoapods

์œ„ ๊ตฌ๋ฌธ์œผ๋กœ ์ •์ƒ์„ค์น˜ ์™„๋ฃŒ!

 

1-2) Cocoapods๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜์ž.

$ pod --version

์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๋˜์—ˆ๋‹ค๋ฉด cocoapods์˜ ๋ฒ„์ „์ด ์ถœ๋ ฅ๋œ๋‹ค.

 

1-3) setup ํ•ด์ฃผ์ž.

$ pod setup --verbose

 

2. Cocoapods ์‚ฌ์šฉํ•˜๊ธฐ

2-1) ํ”„๋กœ์ ํŠธ๋กœ ์ด๋™ํ•ด์„œ pod ๋ฅผ ์‹œ์ž‘ํ•ด์ฃผ์ž

$ pod init

Podfile ์ด ์ƒ์„ฑ๋œ ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

Xcode๋กœ ์—ด์–ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ ํ˜€์žˆ๋‹ค. Podfile๋Š” Ruby ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

 

# platform : ios, '9.0'

์›ํ•˜๋Š” ํ”Œ๋žซํผ๊ณผ ํ”Œ๋žซํผ์˜ ์ตœ์†Œ ๋ฒ„์ „ ์ •์˜

 

3. Podfile์— CLTypingLabel ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด์ž.

pod 'CLTypingLabel'

Podfile์— ์œ„ ๊ตฌ๋ฌธ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์ €์žฅํ•œ๋‹ค.

 

$ pod install

ํ„ฐ๋ฏธ๋„์—์„œ Pod๋กœ ์„ค์น˜ํ•ด์ค€๋‹ค.

 

Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Installing CLTypingLabel (0.4.0)
Generating Pods project
Integrating client project


[!] Please close any current Xcode sessions and use `Flash Chat iOS13.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.


[!] Automatically assigning platform `iOS` with version `13.0` on target `Flash Chat iOS13` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.


[!] Your project does not explicitly specify the CocoaPods master specs repo. Since CDN is now used as the default, you may safely remove it from your repos directory via `pod repo remove master`. To suppress this warning please add `warn_for_unused_master_specs_repo => false` to your Podfile.

์œ„ ๋‚ด์šฉ๊ณผ ํ•จ๊ป˜ ์„ค์น˜๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Pods ํด๋”์™€ ํ•จ๊ป˜ Pod๋ฅผ ๊ฐ–๊ณ  ์žˆ๋Š” xcworkspace ํŒŒ์ผ, CLTypingLabel ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์„ค์น˜๋˜์—ˆ๋‹ค.

 

4. xcworkspace ํ”„๋กœ์ ํŠธ ํŒŒ์ผ ์—ด์–ด์„œ ์‚ฌ์šฉํ•˜๊ธฐ.

xcworkspace ํŒŒ์ผ์—์„  Pods ํŒŒ์ผ์„ ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

4-1) text label ์˜ ํด๋ž˜์Šค๋ฅผ CLTypingLabel ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์ฝ”๋“œ์— ์ ์šฉํ•˜๊ธฐ

import UIKit
import CLTypingLabel

class WelcomeViewController: UIViewController {

    @IBOutlet weak var titleLabel: CLTypingLabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        titleLabel.text = "โšก๏ธFlashChat"
    }
}

for๋ฌธ์œผ๋กœ ๊ธธ๊ฒŒ ๊ตฌํ˜„ํ–ˆ๋˜ ๋ถ€๋ถ„์„ CLTypingLabel ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ํ•œ์ค„๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค.

 

5. ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ญ์ œํ•˜๊ธฐ

Podfile์—์„œ CLTypingLabel ๊ตฌ๋ฌธ์„ ์‚ญ์ œํ•˜๊ณ  ํ„ฐ๋ฏธ๋„์—์„œ ๋‹ค์‹œ pod install ์„ ์‹คํ–‰ํ•ด์ฃผ๋ฉด ์‚ญ์ œ๋œ๋‹ค.

728x90