0

iCloudとiTunesへのバックアップからファイルを除外するために、私は以下のコードを使用しました:

BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]

                              forKey: NSURLIsExcludedFromBackupKey error: &error];

成功の値はYESですが、ファイルの対応する属性を確認したいと思います。以下のコードを使用しようとしましたが、失敗します。

NSLog(@"%@",[URL valueForKey:NSURLIsExcludedFromBackupKey]);

私の目的を達成するための正しい方法は何ですか?ありがとう!

4

1 に答える 1

0

Shashank が示唆したように、を介してリソース値を設定している場合はsetResourceValue、を介してアクセスする必要がありますgetResourceValuevalueForKeyこれは KVC 用であり、リソース値とは関係ありません。

これを行うには、結果を保持するオブジェクトを渡す必要があります。

NSNumber* backupKeyResult = nil;
NSError* error = nil;

BOOL result = [URL getResourceValue:&result forKey:NSURLIsExcludedFromBackupKey error:&error];

if (result && !error) {
   if (backupKeyResult) {
       BOOL backupKeySet = [backupKeyResult boolValue];
       // backupKeySet has the value you've set previously
   }
   else {
        // The requested resource value is not defined for the URL.
   }
}
else {
    if (error) {
        // An error occurred whilst trying this, check your NSError object to see what's up
    }
    else if (!result) {
        // The value was not successfully populated
    }
}
于 2013-02-19T11:58:40.053 に答える