> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/roboflow/roboflow-ko/deploy/sdks/ios-sdk.md).

# iOS SDK

Roboflow Mobile iOS SDK는 더 빠른 inference를 위해 또는 새로운 기능, capabilities, use case(예: augmented reality)를 활용하기 위해 edge(iPad 또는 iPhone)에서 model이 실행되어야 하는 iOS 애플리케이션을 개발하는 경우 훌륭한 옵션입니다.

커스텀 computer vision model이 내장된 네이티브 모바일 애플리케이션을 사용하면 개발자가 앱에 시각을 부여할 수 있습니다.

## 지원 작업

다음 작업 유형이 hosted API에서 지원됩니다:

| 작업 유형                 | iOS SDK Deployment에서 지원 |
| --------------------- | ----------------------- |
| Object Detection      | ✅                       |
| Classification        |                         |
| Instance Segmentation | ✅ (iOS 18 이상)           |
| Semantic Segmentation |                         |

### CoreML Export 호환성

다음 model architecture는 CoreML (`.mlpackage`) export를 통한 on-device deployment를 지원합니다:

| Model                 | CoreML Export |
| --------------------- | ------------- |
| RF-DETR               | ✅             |
| YoloLite              | ✅             |
| Classification models | ✅             |

## iOS Device에 Model 배포하기

### 지원되는 Hardware 및 Software

모든 iOS device는 on-device inference를 지원하지만, iPhone 8(A11 Bionic Processor)보다 오래된 기기는 에너지 효율이 더 낮은 gpu engine으로 fallback됩니다.

Roboflow는 최소 iOS 버전 15.4를 요구합니다(instance segmentation models의 경우 18.0).

## 프로토타이핑

다음을 대상으로 개발할 수 있습니다 [Roboflow Serverless Hosted API](https://docs.roboflow.com/deploy/serverless). 이는 on-device inference와 동일한 trained model을 사용합니다.

## 설치

* 설치 [CocoaPods](https://guides.cocoapods.org/using/getting-started.html) | [문제 해결 가이드](https://guides.cocoapods.org/using/troubleshooting#installing-cocoapods)

"CocoaPods는 Ruby로 만들어졌으며 macOS에서 기본으로 제공되는 Ruby로 설치할 수 있습니다. Ruby Version manager를 사용할 수도 있지만, 무엇을 하고 있는지 잘 아는 경우가 아니라면 macOS에서 제공되는 표준 Ruby를 사용할 것을 권장합니다. 기본 Ruby 설치를 사용하면 `sudo` gems를 설치할 때 사용해야 합니다. (다만 이것은 gem 설치가 진행되는 동안에만 해당되는 문제입니다.)" - [CocoaPods](https://guides.cocoapods.org/using/getting-started.html)

이 과정에서 RubyGems에 admin privileges를 부여하고 싶지 않다면 "Sudo-less" 설치도 선택할 수 있습니다. 그러나 `sudo` 설치가 더 일반적입니다.

다음을 입력하여 CocoaPods가 성공적으로 설치되었는지 확인하세요 `pod --version` 를 Terminal에 입력하세요.

### Roboflow CocoaPod 설치하기

먼저, `pod init` 를 project directory에서 실행하세요.

다음을 확인하세요 `Podfile` 에 다음이 지정되어 있는지 `platform :ios, '15.4'`

다음으로, `pod 'Roboflow'` 를 다음에 추가하세요 `Podfile`.

XCode Command Line Tools가 설치되어 있지 않다면 다음을 실행하세요 `xcode-select --install` 를 Terminal에 입력하세요.

그러면 다음이 반환됩니다: `xcode-select: error: command line tools are alreadyinstalled, use "Software Update" to install updates` 시스템에 Command Line Tools가 이미 있는 경우입니다.

마지막으로, `pod install` 를 실행하고 생성된 `.xcworkspace` 파일을 [XCode](https://developer.apple.com/xcode/).

![Podfile 설치가 성공적으로 완료된 후의 Terminal](/files/f37d0207ddcef8b4cb0ec221c3d95361dad0a205)

![Podfile 설치가 성공적으로 완료된 후의 project directory](/files/4d5eb78bddbac1df0f2a0efdb0451b69e2093e41)

* 다음 오류가 반환된다면: "You may have encountered a bug in the Ruby interpreter or extension libraries," 먼저 다음을 실행하세요 `brew install cocoapods`, 그런 다음 `pod install` 를 실행하고 생성된 `.xcworkspace` 파일을 XCode에서 여세요.
  * 다음을 입력하여 CocoaPods가 성공적으로 설치되었는지 확인하세요 `pod --version` 를 Terminal에 입력하세요.

### Swift에서 Roboflow 사용하기

다음으로 이동하세요 `.xcworkspace` 파일을 XCode에서 여세요.

![](/files/82eb13b1ea5bdb7077d5e44352f516c356b3bbb5)

다음으로, 다음을 추가하여 Roboflow를 import하세요 `import Roboflow`를 `.xcworkspace` file에 추가하세요.

그런 다음 다음과 같이 Roboflow API 인스턴스를 생성하세요 `let rf = Roboflow(apiKey: "API_KEY")`.  `modelVersion`의 경우, `YOUR-MODEL-VERSION-#` 를 model version 번호의 정수 값으로 바꾸세요.

#### Project 정보 찾기

**Completion Handler 사용:**

```swift
import Roboflow
...
//API Key로 초기화
let rf = RoboflowMobile(apiKey: "API_KEY")
var model: RFModel?
...

//model은 model의 project name입니다
rf.load(model: "YOUR-MODEL-ID", modelVersion: YOUR-MODEL-VERSION-#) { [self] model, error, modelName, modelType in
    if error != nil {
        print(error?.localizedDescription as Any)
    } else {
        model?.configure(threshold: threshold, overlap: overlap, maxObjects: maxObjects
                            processingMode: .performance 또는 .balanced 또는 .quality, // instance seg
                            maxNumberPoints: mask processing point의 최대 수) // instance seg
        self.model = model
    }
    
}
...

//model?.detect는 UIImage를 받아 그 위에서 inference를 실행합니다
let img = UIImage(named: "example.jpeg") // 또는 CVPixelBuffer
model?.detect(image: img!) { predictions, error in
    if error != nil {
        print(error)
    } else {
        print(predictions)
    }
}
```

**비동기 사용:**

비동기로 사용하려면 비동기 block 내에서 Roboflow model을 호출해야 합니다.

```swift
import Roboflow
...
//API Key로 초기화
let rf = RoboflowMobile(apiKey: "API_KEY")
...

//model은 model의 project name입니다
let (model, loadingError, modelName, modelType) = await rf.load(model: "YOUR-MODEL-ID", modelVersion: YOUR-MODEL-VERSION-#)
model!.configure(threshold: threshold, overlap: overlap, maxObjects: maxObjects)
...

//model?.detect는 UIImage를 받아 그 위에서 inference를 실행합니다
let img = UIImage(named: "example.jpeg")
let (predictions, predictionError) = await model!.detect(image: img!)
print(predictions)
```

**Predictions 형식:**

```
x:Float //object x의 중심
y:Float //object y의 중심
width:Float
height:Float
className:String
confidence:Float
color:UIColor
box:CGRect
points:[CGPoint] // instance segmentation models 전용
```

[CGRect](https://developer.apple.com/documentation/corefoundation/cgrect)

### 네이티브 Swift 예제

해당 [roboflow-ios-starter](https://github.com/roboflow/roboflow-ios-starter) app은 Roboflow model로 realtime iOS app을 만들기 위한 훌륭한 시작점입니다. 여기에는 object-detection 및 instance segmentation model 모두에 대한 camera 설정, model loading 및 processing, output drawing code가 포함되어 있습니다.

### React Native Expo App 예제

또한 여기에서 React Native를 사용한 expo app에 이 SDK를 통합하는 예제도 제공합니다. 자체 downstream application 구성을 고려할 때 유용할 수 있습니다.

다음 둘 다 설치되어 있는지 확인하세요 [Expo](https://docs.expo.dev/) 및 [CocoaPods](https://guides.cocoapods.org/using/getting-started.html) 설치되어 있습니다.

* `expo-cli` 는 다음 Node.js 버전을 지원합니다: `>=12.13.0 <15.0.0` (Maintenance LTS) 및 `>=16.0.0 <17.0.0` (Active LTS)
* Node.js용 yarn package가 설치되어 있어야 합니다 (`npm install -g yarn`)

{% embed url="<https://github.com/roboflow-ai/RoboflowExpoExample>" %}

### 예제 iOS 애플리케이션 - CashCounter

다운로드 [CashCounter](https://apps.apple.com/app/roboflow-cash-counter/id1633812788), 미국 동전과 지폐를 세는 예제 iOS app으로, computer vision model을 iPhone에 배포하는 방법의 예시입니다. bounding box 시각화, FPS, object counting, image upload 등의 예제를 볼 수 있습니다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.roboflow.com/roboflow/roboflow-ko/deploy/sdks/ios-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
