---
title: CKRecord
framework: cloudkit
role: symbol
role_heading: Class
path: cloudkit/ckrecord
---

# CKRecord

A collection of key-value pairs that store your app’s data.

## Declaration

```swift
class CKRecord
```

## Mentioned in

Designing and Creating a CloudKit Database Encrypting User Data

## Overview

Overview Records are the fundamental objects that manage data in CloudKit. You can define any number of record types for your app, with each record type corresponding to a different type of information. Within a record type, you then define one or more fields, each with a name and a value. Records can contain simple data types, such as strings and numbers, or more complex types, such as geographic locations or pointers to other records. An important step in using CloudKit is defining the record types your app supports. A new record object doesn’t contain any keys or values. During development, you can add new keys and values at any time. The first time you set a value for a key and save the record, the server associates that type with the key for all records of the same type. The CKRecord class doesn’t impose these type constraints or do any local validation of a record’s contents. CloudKit enforces these constraints when you save the records. note: The ability to add new keys is only possible during development. When you deploy to a production environment, the server returns an error if you try to specify an unknown record type or try to save a record that contains unknown keys. Although records behave like dictionaries, there are limitations to the types of values you can assign to keys. The following are the object types that the CKRecord class supports. Attempting to specify objects of any other type results in failure. Fields of all types are searchable unless otherwise noted. Supported Data Types CKRecord fields support the following data types: important: To ensure the speed of fetching and saving records, the data that a record stores must not exceed 1 MB. Assets don’t count toward this limit, but all other data types do. Defining Records The process for defining your record types depends entirely on your app and the data you’re trying to represent. It’s best to design records that encapsulate data for one unit of information. For example, you might use one record type to store an employee’s name, job title, and date of hire, and use a separate record type to store the employee’s address information. Using different record types lets you manage, manipulate, and validate the two types of information separately. Use fields that contain CKRecord.Reference objects to establish relationships between different types of records. After you define your record types, use the iCloud Dashboard to set them up. During development, you can also create new record types programmatically. Indexing the Fields of a Record Indexes make it possible to search the contents of your records efficiently. During development, the server indexes all fields with data types it can use in the predicate of a query. This automatic indexing makes it easier to experiment with queries during development, but the indexes require space in a database, and require time to generate and maintain. To manage the indexing behavior of your records in the production environment, use CloudKit Dashboard. When migrating your schema from the development environment to the production environment, enable indexing only for the fields that your app uses in queries, and disable it for all other fields. Customizing Records Use this class as-is to manage data coming from or going to the server, and don’t subclass it. Storing Records Locally If you store records in a local database, use the encodeSystemFields(with:) method to encode and store the record’s metadata. The metadata contains the record ID and the change tag, which you need later to sync records in a local database with those in CloudKit.

## Topics

### Creating a Record

- [init(recordType:recordID:)](cloudkit/ckrecord/init(recordtype:recordid:).md)
- [CKRecord.RecordType](cloudkit/ckrecord/recordtype-swift.typealias.md)
- [CKRecord.FieldKey](cloudkit/ckrecord/fieldkey.md)
- [init(recordType:zoneID:)](cloudkit/ckrecord/init(recordtype:zoneid:).md)

### Accessing the Record’s Fields

- [object(forKey:)](cloudkit/ckrecord/object(forkey:).md)
- [subscript(_:)](cloudkit/ckrecord/subscript(_:)-51whk.md)
- [subscript(_:)](cloudkit/ckrecord/subscript(_:)-4g91i.md)
- [setObject(_:forKey:)](cloudkit/ckrecord/setobject(_:forkey:).md)
- [allKeys()](cloudkit/ckrecord/allkeys().md)
- [changedKeys()](cloudkit/ckrecord/changedkeys().md)
- [makeIterator()](cloudkit/ckrecord/makeiterator().md)
- [CKRecordKeyValueIterator](cloudkit/ckrecordkeyvalueiterator.md)
- [CKRecordValueProtocol](cloudkit/ckrecordvalueprotocol.md)
- [CKRecordKeyValueSetting](cloudkit/ckrecordkeyvaluesetting.md)
- [CKRecordValue](cloudkit/ckrecordvalue-swift.typealias.md)

### Accessing the Record’s Metadata

- [recordID](cloudkit/ckrecord/recordid.md)
- [recordType](cloudkit/ckrecord/recordtype-6v7au.md)
- [CKRecord.SystemType](cloudkit/ckrecord/systemtype.md)
- [creationDate](cloudkit/ckrecord/creationdate.md)
- [creatorUserRecordID](cloudkit/ckrecord/creatoruserrecordid.md)
- [modificationDate](cloudkit/ckrecord/modificationdate.md)
- [lastModifiedUserRecordID](cloudkit/ckrecord/lastmodifieduserrecordid.md)
- [recordChangeTag](cloudkit/ckrecord/recordchangetag.md)
- [CKRecord.ID](cloudkit/ckrecord/id.md)

### Encrypting the Record’s Values

- [encryptedValues](cloudkit/ckrecord/encryptedvalues.md)

### Getting Data for Full-Text Searches

- [allTokens()](cloudkit/ckrecord/alltokens().md)

### Encoding the Record’s Metadata

- [encodeSystemFields(with:)](cloudkit/ckrecord/encodesystemfields(with:).md)

### Sharing Records

- [parent](cloudkit/ckrecord/parent.md)
- [share](cloudkit/ckrecord/share.md)
- [CKRecord.Reference](cloudkit/ckrecord/reference.md)
- [setParent(_:)](cloudkit/ckrecord/setparent(_:)-23du1.md)
- [setParent(_:)](cloudkit/ckrecord/setparent(_:)-7egcx.md)
- [CKRecord.SystemFieldKey](cloudkit/ckrecord/systemfieldkey.md)

### Initializers

- [init(coder:)](cloudkit/ckrecord/init(coder:).md)

### Default Implementations

- [Sequence Implementations](cloudkit/ckrecord/sequence-implementations.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [CKShare](cloudkit/ckshare.md)

### Conforms To

- [CKRecordKeyValueSetting](cloudkit/ckrecordkeyvaluesetting.md)
- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Sequence](swift/sequence.md)

## See Also

### Schemas

- [Designing and Creating a CloudKit Database](cloudkit/designing-and-creating-a-cloudkit-database.md)
- [Managing iCloud Containers with CloudKit Database App](cloudkit/managing-icloud-containers-with-cloudkit-database-app.md)
- [CKRecordZone](cloudkit/ckrecordzone.md)
- [CKRecord.Reference](cloudkit/ckrecord/reference.md)
- [CKAsset](cloudkit/ckasset.md)
- [Integrating a Text-Based Schema into Your Workflow](cloudkit/integrating-a-text-based-schema-into-your-workflow.md)
