티스토리 뷰



cocoapods (코코아팟) 이란?


의존성 라이브러리 관리 툴.

안드로이드의 Gradle 이 하는 역할과 비슷하다.


기존에 Library 들의 import 를 일일히 수동으로 하고,

Library Dependency 문제로 앓았던 골머리를 해결해 준다.






How to use the cocoapods ?


Step 1> install cocoapods


터미널을 열어 아래의 명령어를 입력해 줍니다. (아무데서나)


$ sudo gem install cocoapods





Step 2> pod init


터미널을 이용하여 우리가 cocoapods 를 이용할 프로젝트 폴더로 들어갑니다.

그 후 아래의 명령어를 입력해 줍니다.


$ pod init


잠시간 대기 후 에러메세지가 없다면, 

아래와 같이 프로젝트 폴더에 Podfile 이 생성된다.








Step 3> vi Podfile


init 후 터미널에서 바로 Podfile 을 들어간다.


초기라면 아래와 같이 보일 것이다.


# Uncomment the next line to define a global platform for your project

# platform :ios, '9.0'


target 'Test' do

  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks

  use_frameworks!


  # Pods for Test


end


우선, 테스트 해보려면 우리는 무언가 라이브러리를 추가해야 한다.


https://cocoapods.org 에서 적당한 라이브러리를 찾아서 추가해보자.


나는 'RealmSwift' library 를 추가해보기로 했다.


Podfile 을 아래와같이 수정한다.


# Uncomment the next line to define a global platform for your project

# platform :ios, '9.0'


target 'Test' do

  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks

  use_frameworks!

  pod 'RealmSwift'

  # Pods for Test

end




위의 빨간색 부분 처럼 적고, 저장하여 빠져나온다.








Step 4> pod install


터미널로 돌아와 아래의 명령어를 기입한다.


$ pod install


터미널 명령어가 실행되면서, 아래의 문구를 볼 수 있을 것이다.


Analyzing dependencies

Downloading dependencies

Installing Realm (3.6.0)

Installing RealmSwift (3.6.0)

Generating Pods project

Integrating client project

Sending stats

Pod installation complete! There is 1 dependency from the Podfile and 2 total pods installed.


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








Step 5> 실행



우리가 보통 실행하는 .xcodeproj 파일 말고, 

.xcworkspace 로 실행해야 한다.


xcode 를 .xcworkspace 파일을 이용해 실행하자.







Step 6> import


프로젝트가 정상적으로 오픈되었다면, 파일을 열어 아래와 같이 import 할 수 있고, 

이제 라이브러리를 이용할 수 있다.


import RealmSwift



설치 이슈


1. [Xcodeproj] Unknown object version.


cocoapods 가 설치되지 않았음.


$ sudo gem install cocoapods 를 입력하여 설치 후 pod init 실행









2. No such module ..


설치한 라이브러리가 스킴에 포함되어있지 않아 발생하는 문제.

아래 방법을 따라해보자


1) manage scheme




2) 체크








공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함