LoginSignup
4
5

More than 5 years have passed since last update.

Realmで保存場所を指定する方法

Posted at
//Realm保存用のディレクトリ
#define REALM_DIR_PATH @"/Library/Caches/jp.co.apps.xxxx/"

//Realmファイル名
#define REALM_FILE_NAME @"default.realm"



#pragma mark --RealmをConfigurationオブジェクト使って作成
-(RLMRealm *)createRealmWithConfiguration
{
    NSString *realmDirPath = [NSHomeDirectory() stringByAppendingPathComponent:REALM_DIR_PATH];
    realmDirPath = [realmDirPath stringByAppendingPathComponent:REALM_FILE_NAME];

    // declarations
    RLMRealmConfiguration *configuration = [RLMRealmConfiguration defaultConfiguration];
    configuration.fileURL = [NSURL fileURLWithPath:realmDirPath];

    RLMRealm *realm = [RLMRealm realmWithConfiguration:configuration error:nil];

    return realm;
}

こんな感じです。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5