본문 바로가기
iOS

[iOS - MongoDB Realm] 4-1. iOS SDK - Install Realm for iOS

by 건복치 2020. 12. 15.
반응형
MongoDB Realm Documentaion을 보고 정리한 내용입니다.

이를 바탕으로 MongoDB Realm을 이용한 iOS 앱을 만들 것입니다.
따라서 iOS 개발 관련 부분만 정리할 예정입니다.

MongoDB Realm Documentation 중 현재 포스트의 부분은 아래와 같습니다.
MongoDB Realm - iOS SDK - Install Realm for iOS
 

Install Realm for iOS, macOS, tvOS, and watchOS — MongoDB Realm

Add the line use_frameworks! if it is not already there. Add the line pod 'RealmSwift', '=10.1.4' to your main and test targets. When done, your Podfile should look something like this: platform :ios, '12.0'target 'MyRealmProject' do # Comment the next lin

docs.mongodb.com


[iOS - MongoDB Realm] 포스트

[iOS - MongoDB Realm] 1. MongoDB Realm
[iOS - MongoDB Realm] 2. Get Started - Introduction to MongoDB Realm for Mobile Developers
[iOS - MongoDB Realm] 3. Tutorial - Create a Task Tracker App - iOS Swift Tutorial
[iOS - MongoDB Realm] 3-1. Tutorial - Set up the Task Tracker Tutorial Backend
[iOS - MongoDB Realm] 3-2. Tutorial - iOS Swift Tutorial
[iOS - MongoDB Realm] 4. iOS SDK
[iOS - MongoDB Realm] 4-1. iOS SDK - Install Realm for iOS
[iOS - MongoDB Realm] 4-2. iOS SDK - Quick Start
next

개요 

MongoDB Realm의 Apple 플랫폼 SDK를 사용하면 iOS, macOS, tvOS 및 watchOS 애플리케이션이

Swift 또는 Objective-C 프로그래밍 언어를 사용하여 MongoDB Realm과 상호 작용할 수 있습니다. 

이 페이지는 프로젝트에 Realm을 설치하고 시작하는 방법을 자세히 설명합니다.

 

Swift 언어로만 진행할 예정입니다.

전제 조건 

시작하기 전에 개발 환경이 다음 전제 조건을 충족하는지 확인하십시오.

  • Xcode 버전 10.0 이상.
  • iOS 8.0 이상, macOS 10.9 이상, tvOS 9.0 이상 또는 watchOS 2.0 이상을 대상으로 합니다.
  • CocoaPods로 설치하는 경우 CocoaPods 1.10.0 이상이 필요합니다.

설치 

프로젝트에 MongoDB Realm Apple 플랫폼 SDK를 추가하기 위해 아래의 SwiftPM 또는 CocoaPods의 방법을 따르세요.

SwiftPM 

1. 패키지 종속성 추가 

Xcode 에서 File> Swift Packages> Add Package Dependency 선택.

2. 저장소 지정 

다음을 복사하여 검색 / 입력 상자에 붙여 넣은 다음 Next를 클릭합니다.

 

https://github.com/realm/realm-cocoa.git

3. 옵션 지정 

기본값을 다음 단계까지 유지한 후 Next를 클릭합니다.

(Leave the default value of Up to Next Major, then click Next.)

4. 패키지 제품 선택 

Realm과 RealmSwift를 모두 선택한 다음 Finish를 클릭합니다.

 

CocoaPods 

1. CocoaPods 저장소 업데이트 

pod repo update

 

명령줄에서 pod repo update 명령어로 CocoaPods이 최신 Realm 버전에 액세스 할 수 있는지 확인하십시오.

2. 프로젝트의 CocoaPods 초기화 

pod init

 

프로젝트에 아직 Podfile이 없는 경우 프로젝트의 루트 디렉터리에서 pod init 명령어를 실행하여 프로젝트에 대한 Podfile을 만듭니다.

Podfile이 만들어지면 CocoaPods에 대한 프로젝트 종속성을 지정할 수 있습니다.

3. Podfile에 Realm을 종속성으로 추가

use_frameworks! 

가 아직 없는 경우 이 행을 추가하십시오.

 

pod 'RealmSwift', '=10.0.0-beta.6' 을 추가하십시오.

 

Realm을 추가한 완성된 Podfile은 아래와 같습니다.

 

platform :ios, '12.0'

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

  # Pods for MyRealmProject
  pod 'RealmSwift', '=10.0.0-beta.6'

end

4. 종속성 설치 

pod install

 

pod install 명령을 실행해 종속성을 가져옵니다.

5. CocoaPods 생성. xcworkspace파일 사용 

CocoaPods는. xcworkspace파일을 생성합니다. 

이 파일에는 모든 종속성이 구성되어 있습니다. 

이제부터. xcodeproj 파일이 아니라. xcworkspace 파일에서 작업합니다.

Realm 가져오기

MongoDB Realm을 사용하려면 소스 파일 상단에 다음 줄을 추가하세요.

import RealmSwift
반응형

댓글