iOS/UIKit

[UIKit] : CocoaPods 설치, 라이브러리 (SnapKit + Then)사용하기

SeorinY 2022. 9. 20. 12:45

SnapKit, Then 등 외부라이브러리를 사용하기 위해 CocoaPods 을 설치해보자!!

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

위 링크로 접속하면 

$ sudo gem install cocoapods

이라는 명령어가 나올 것이다. 

위 명령어를 통해 컴퓨터에 CocoaPods을 설치해주자.

 

꼭 사용할 프로젝트 경로에서 설치해줄 필요는 없다.

 

이제 SnapKit, Then을 사용하기 위해 프로젝트 내에  Pods 파일을 생성해주자.

 

우선 cd 명령어로 프로젝트 저장소로 이동하고

$ pod init

 

 

를 입력하자

 

Podfile이 생성된 것을 볼 수 있다!

이제 Pod 파일에 사용하고자 하는 라이브러리 (SnapKit, Then) 를 명시해주기만 하면 완성이다.

 

Podfile을 아래처럼 수정해주자.

라이브러리 버전 작성은 CocoaPods 공식 사이트를 참고하면 된다

https://cocoapods.org/pods/SnapKit

 

SnapKit

Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.

cocoapods.org

https://cocoapods.org/pods/Then

 

Then

Super sweet syntactic sugar for Swift initializers.

cocoapods.org

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'BlogCode' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for BlogCode

  pod 'SnapKit', '~> 5.0.0'
  pod 'Then'


end

Podfile을 위처럼 수정했다면

$ pod install

를 입력하여 라이브러리를 다운받자.

 

이제 코드에서  import하여 라이브러리를 사용할 수 있게 되었다!@@