티스토리 뷰

iOS

[iOS] CocoaPods 설치 및 사용방법

반해원 2024. 5. 14. 11:07

안녕하세요. 반해원입니다.

 

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

 

 

🤔 CocoaPods란?

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 100 thousand libraries and is used in over 3 million apps. CocoaPods can help you scale your projects elegantly.

 

Swift와 Objective-C 코코아 프로젝트의 의존성 관리자로, 100,000개가 넘는 라이브러리를 가지고 있으며 3백만 개의 앱 이상에서 쓰이고 있답니다.

 

😎 CocoaPods 설치

터미널을 열어 아래 명령어를 입력해 줍니다.

$ sudo gem install cocoapods

 

그럼 설치 끝!

 

🥸 Podfile 생성 및 작성

터미널에서 Xcode 프로젝트 경로로 이동합니다.

그리고 아래 명령어를 입력해 줍니다.

$ pod init

 

그럼 이제 해당 경로에 Podfile 이라는 새로운 파일이 생성되었습니다.

 

원하는 라이브러리 정보를 요 Podfile에 적용해주면 됩니다.

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

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

  # Pods for BanProject

end

 

저는 SnapKit을 적용하기 위해 아래처럼 수정하겠습니다.

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

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

  # Pods for BanProject
  pod 'SnapKit', '~> 5.7.0'
end

 

Podfile 수정이 완료되었으면 다시 터미널로 돌아와서 아래 명령어를 입력해 줍니다.

$ pod install

 

이제 프로젝트 경로에 들어가 보면

.xcworkspace 파일이 생겼을 텐데 이 파일을 이용해서 프로젝트를 열어주면 됩니다.

Pods 폴더도 새롭게 추가되었습니다.

 

import SnapKit
...

 

이제 소스코드에서 Podfile에 추가한 SnapKit 라이브러리를 import 하여 사용할 수 있습니다.

후후

 

만약 새로운 라이브러리를 추가하거나 삭제하려면 위와 동일하게

Podfile을 수정하고 Pod install 명령어를 실행하면 됩니다.

 

끝입니다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함