<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CloudKit",
  "identifier" : "/documentation/CloudKit/CKContainer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "c:objc(cs)CKContainer"
  },
  "title" : "CKContainer"
}
-->

# CKContainer

A conduit to your app’s databases.

```
class CKContainer
```

## Overview

A container manages all explicit and implicit attempts to access its contents.

Every app has a default container that manages its own content. If you develop a suite of apps, you can access any containers that you have the appropriate entitlements for. Each new container distinguishes between public and private data. CloudKit always stores private data in the appropriate container directory in the user’s iCloud account.

> Note: `CKContainer` instances operate with a <doc://com.apple.documentation/documentation/Foundation/QualityOfService/userInitiated> quality of service level by default. For information about quality of service, see [Prioritize Work with Quality of Service Classes](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html#//apple_ref/doc/uid/TP40015243-CH39) in [Energy Efficiency Guide for iOS Apps](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/index.html#//apple_ref/doc/uid/TP40015243) and [Prioritize Work at the Task Level](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/PrioritizeWorkAtTheTaskLevel.html#//apple_ref/doc/uid/TP40013929-CH35) in [Energy Efficiency Guide for Mac Apps](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/index.html#//apple_ref/doc/uid/TP40013929).

### Interacting with a Container

A container coordinates all interactions between your app and the server. Most of these interactions involve the following tasks:

- Determining whether the user has an iCloud account, which lets you know if you can write data to the user’s personal storage.
- With the user’s permission, discovering other users who the current user knows, and making the current user’s information discoverable.
- Getting the container or one of its databases to use with an operation.

### Public and Private Databases

Each container provides a public and a private database for storing data. The contents of the public database are accessible to all users of the app, whereas the contents of the private database are, by default, visible only to the current user. Content that is specific to a single user usually belongs in that user’s private database, whereas app-related content that you provide (or that users want to share) belongs in the public database.

The public database is always available, regardless of whether the device has an active iCloud account. When there isn’t an iCloud account, your app can fetch records from and query the public database, but it can’t save changes. Saving records to the public database requires an active iCloud account to identify the owner of those records. Access to the private database always requires an active iCloud account on the device.

> Note: The data in a public database counts toward the iCloud storage quota of the app that owns the container. That data doesn’t count toward the storage quota of any single user. Data in the private database counts toward the user’s iCloud storage quota.

### Using iCloud

Whenever possible, design your app to run gracefully with or without an active iCloud account. Even without an active iCloud account, apps can fetch records from the public database and display that information to the user. If your app requires the ability to write to the public database or requires access to the private database, notify the user of the reason and encourage them to enable iCloud. You can even provide a button that takes the user directly to Settings so that they can enable iCloud. To implement such a button, have the button’s action open the URL that the <doc://com.apple.documentation/documentation/UIKit/UIApplication/openSettingsURLString> constant provides.

### User Records and Permissions

When a user accesses a container for the first time, CloudKit assigns them a unique identifier and uses it to create two user records — one in the app’s public database and another in that user’s private database. By default, these records don’t contain any identifying personal information, but you can use the record in the user’s private database to store additional, nonsensitive information about that user. Because the public database’s user record is accessible to all users of your app, don’t use it to store information about the user.

While a user record isn’t the same as the user’s [`CKUserIdentity`](/documentation/CloudKit/CKUserIdentity), the identity does provide the identifier of their user record that you can use to fetch that record from either the public database or the user’s private database. For more information, see [`userRecordID`](/documentation/CloudKit/CKUserIdentity/userRecordID).

### Testing Your Code Using the Development Container

At runtime, CloudKit uses your app’s `com.apple.developer.icloud-container-environment` entitlement to discover whether you’re using a `Development` or `Production` version of your provisioning profile. When you configure the entitlement for development, CloudKit configures the app’s containers to use the development server. The development environment is a safe place to make changes during the development process without disrupting users of your app. You can add new fields to records programmatically, and you can delete or modify fields using iCloud Dashboard.

Before shipping your app, always test your app’s behavior in the production environment. The production server generates errors when your app tries to add record types or add new fields to existing record types. Testing in the production environment helps you find and fix the places in your code where you’re making those types of changes. You can use CloudKit Dashboard to modify record types in the development environment, and then migrate those changes to the production environment.

> Note: Simulator works only with the development environment. When you’re ready to test your app in a production environment, do so from a device.

## Topics

### Creating Containers

[`default()`](/documentation/CloudKit/CKContainer/default())

Returns the app’s default container.

[`init(identifier:)`](/documentation/CloudKit/CKContainer/init(identifier:))

Creates a container for the specified identifier.

### Getting the Public and Private Databases

[`privateCloudDatabase`](/documentation/CloudKit/CKContainer/privateCloudDatabase)

The user’s private database.

[`publicCloudDatabase`](/documentation/CloudKit/CKContainer/publicCloudDatabase)

The app’s public database.

[`sharedCloudDatabase`](/documentation/CloudKit/CKContainer/sharedCloudDatabase)

The database that contains shared data.

[`database(with:)`](/documentation/CloudKit/CKContainer/database(with:))

Returns the database with the specified scope.

### Getting the Container’s Identifier

[`containerIdentifier`](/documentation/CloudKit/CKContainer/containerIdentifier)

The container’s unique identifier.

### Determining the User’s iCloud Access Status

[`accountStatus(completionHandler:)`](/documentation/CloudKit/CKContainer/accountStatus(completionHandler:))

Determines whether the system can access the user’s iCloud account.

[`CKAccountStatus`](/documentation/CloudKit/CKAccountStatus)

Constants that indicate the availability of the user’s iCloud account.

### Requesting and Determining App Permissions

[`requestApplicationPermission(_:completionHandler:)`](/documentation/CloudKit/CKContainer/requestApplicationPermission(_:completionHandler:))

Prompts the user to authorize the specified permission.

[`status(forApplicationPermission:completionHandler:)`](/documentation/CloudKit/CKContainer/status(forApplicationPermission:completionHandler:))

Determines the authorization status of the specified permission.

[`CKContainer.Application`](/documentation/CloudKit/CKContainer/Application)

A collection of types for app permissions.

[`CKContainer.ApplicationPermissions`](/documentation/CloudKit/CKContainer/ApplicationPermissions)

Constants that represent the permissions that a user grants.

[`CKContainer.ApplicationPermissionBlock`](/documentation/CloudKit/CKContainer/ApplicationPermissionBlock)

A closure that processes the outcome of a permissions request.

[`CKContainer.ApplicationPermissionStatus`](/documentation/CloudKit/CKContainer/ApplicationPermissionStatus)

Constants that represent the status of a permission.

### Performing Operations on the Container

[`add(_:)`](/documentation/CloudKit/CKContainer/add(_:))

Adds an operation to the container’s queue.

### Discovering User Records

[`discoverAllIdentities(completionHandler:)`](/documentation/CloudKit/CKContainer/discoverAllIdentities(completionHandler:))

Fetches all user identities that match entries in the user’s Contacts.

[`discoverUserIdentity(withEmailAddress:completionHandler:)`](/documentation/CloudKit/CKContainer/discoverUserIdentity(withEmailAddress:completionHandler:))

Fetches the user identity for the specified email address.

[`discoverUserIdentity(withPhoneNumber:completionHandler:)`](/documentation/CloudKit/CKContainer/discoverUserIdentity(withPhoneNumber:completionHandler:))

Fetches the user identity for the specified phone number.

[`discoverUserIdentity(withUserRecordID:completionHandler:)`](/documentation/CloudKit/CKContainer/discoverUserIdentity(withUserRecordID:completionHandler:))

Fetches the user identity for the specified user record ID.

[`fetchShareParticipant(withEmailAddress:completionHandler:)`](/documentation/CloudKit/CKContainer/fetchShareParticipant(withEmailAddress:completionHandler:))

Fetches the share participant with the specified email address.

[`fetchShareParticipant(withPhoneNumber:completionHandler:)`](/documentation/CloudKit/CKContainer/fetchShareParticipant(withPhoneNumber:completionHandler:))

Fetches the share participant with the specified phone number.

[`fetchShareParticipant(withUserRecordID:completionHandler:)`](/documentation/CloudKit/CKContainer/fetchShareParticipant(withUserRecordID:completionHandler:))

Fetches the share participant with the specified user record ID.

[`fetchUserRecordID(completionHandler:)`](/documentation/CloudKit/CKContainer/fetchUserRecordID(completionHandler:))

Fetches the user record ID of the current user.

[`CKCurrentUserDefaultName`](/documentation/CloudKit/CKCurrentUserDefaultName)

A constant that provides the current user’s default name.

[`CKOwnerDefaultName`](/documentation/CloudKit/CKOwnerDefaultName)

A constant that provides the default owner’s name.

### Fetching Long-Lived Operations

[`fetchAllLongLivedOperationIDs(completionHandler:)`](/documentation/CloudKit/CKContainer/fetchAllLongLivedOperationIDs(completionHandler:))

Fetches the IDs of any long-lived operations that are running.

[`fetchLongLivedOperation(withID:completionHandler:)`](/documentation/CloudKit/CKContainer/fetchLongLivedOperation(withID:completionHandler:))

Fetches the long-lived operation for the specified operation ID.

[`fetchAllLongLivedOperationIDsWithCompletionHandler:`](/documentation/CloudKit/CKContainer/fetchAllLongLivedOperationIDsWithCompletionHandler:)

Fetches the IDs of any long-lived operations that are running.

[`fetchLongLivedOperationWithID:completionHandler:`](/documentation/CloudKit/CKContainer/fetchLongLivedOperationWithID:completionHandler:)

Fetches the long-lived operation for the specified operation ID.

### Accessing Container Metadata

[`fetchShareMetadata(with:completionHandler:)`](/documentation/CloudKit/CKContainer/fetchShareMetadata(with:completionHandler:))

Fetches the share metadata for the specified share URL.

[`accept(_:completionHandler:)`](/documentation/CloudKit/CKContainer/accept(_:completionHandler:)-949ea)

Accepts the specified share metadata.

[`CKAccountChangedNotification`](/documentation/CloudKit/CKAccountChangedNotification)

A notification that a container posts when the status of an iCloud account changes.

### Accessing Container Metadata

[`fetchShareMetadata(with:completionHandler:)`](/documentation/CloudKit/CKContainer/fetchShareMetadata(with:completionHandler:))

Fetches the share metadata for the specified share URL.

[`accept(_:completionHandler:)`](/documentation/CloudKit/CKContainer/accept(_:completionHandler:)-949ea)

Accepts the specified share metadata.

[`CKAccountChangedNotification`](/documentation/CloudKit/CKAccountChangedNotification)

A notification that a container posts when the status of an iCloud account changes.

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/CKAccountChanged>



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)