---
title: Encrypting a Model in Your App
framework: coreml
role: article
role_heading: Article
path: coreml/encrypting-a-model-in-your-app
---

# Encrypting a Model in Your App

Encrypt your app’s built-in model at compile time by adding a compiler flag.

## Overview

Overview Tell Xcode to encrypt your model as it compiles your app by adding a compiler flag to your build target. Add a compiler flag In Xcode, navigate to your project’s target and open its Build Phases tab. Expand the Compile Sources section and select the model you want Xcode to encrypt at compile time. Open the model’s compiler flags editor by double-clicking the model’s entry. In the editor, add: The encryption flag “--encrypt” A space character The absolute path to the model’s encryption key file you created (see Generating a Model Encryption Key), between quotation marks Press the Return key or click outside the editor to close it.

Load the model At runtime, you load the encrypted model the same way you load any other built-in model by using its load(completionHandler:completionHandler:) type method. This method behaves similarly to the MLModel type method loadContentsOfURL:configuration:completionHandler: and creates an instance of the model using the convenience class that Xcode generates.

## See Also

### Model encryption

- [Generating a Model Encryption Key](coreml/generating-a-model-encryption-key.md)
