Back to Realm Swift

Build for tvOS

docs/guides/realm-files/tvos.md

20.0.41.6 KB
Original Source

Build for tvOS

Overview

This page details considerations when using Realm on tvOS.

Seealso: Install the SDK for iOS, macOS, tvOS, and watchOS

Avoid Storing Important User Data

Avoid storing important user data in a realm on tvOS. Instead, it's best to treat Realm as a rebuildable cache.

Note: The reason for this has to do with where Realm writes its Realm files. On other Apple platforms, Realm writes its Realm files to the "Documents" directory. Because tvOS restricts writes to that directory, the default Realm file location on tvOS is instead NSCachesDirectory. tvOS can purge files in that directory at any time, so reliable long-term persistence is not possible.

You can also use Realm as an initial data source by bundling prebuilt Realm files in your app. Note that the App Store guidelines limit your app size to 4GB.

Tip: Browse our tvOS examples for sample tvOS apps that demonstrate how to use Realm as an offline cache.

Share Realm Files with TV Services Extensions

To share a Realm file between a tvOS app and a TV services extension such as Top Shelf, use the Library/Caches/ directory in the shared container for the application group:

swift
let fileUrl = FileManager.default
    .containerURL(forSecurityApplicationGroupIdentifier: "group.com.mongodb.realm.examples.extension")!
    .appendingPathComponent("Library/Caches/default.realm")