2016-07-16 8 views
5

私のアプリは、「起動時およびコンテンツダウンロード時に、iOSデータストレージガイドラインに準拠していないユーザーのiCloudに13.01 MBを保存します。キャッシュディレクトリにレルムファイルをコピー

問題がわかりました。ドキュメントディレクトリではなく、キャッシュディレクトリにレルムデータベースを保存できますか?

+0

http://stackoverflow.com/questions/8489342/xcode-ios-trying-to-copy-files-to-caches-folder-on-install –

+0

...も参照してください。これは私が望むものではありません。 –

答えて

4

Realm.Configuration.fileURLを使用すると、レルムファイルパスを変更できます。

let cachesDirectoryPath = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0] 
let cachesDirectoryURL = NSURL(fileURLWithPath: cachesDirectoryPath) 
let fileURL = cachesDirectoryURL.URLByAppendingPathComponent("Default.realm") 

let config = Realm.Configuration(fileURL: fileURL) 
let realm = try! Realm(configuration: config) 

あなたはfileURLすべてのインスタンスのレルムを指定したくない場合は、Realm.Configuration.defaultConfigurationを使用することができます。以下のように。構成オブジェクトをdefaultConfigurationに設定すると、Realm()はこの構成をデフォルトとして使用します。

Realm.Configuration.defaultConfiguration = config 
let realm = Realm() 

https://realm.io/docs/swift/latest/#realm-configuration

関連する問題