0

デバイスのドキュメントフォルダにあるファイルのファイルパスをコアデータエンティティに保存しようとすると、正しく挿入されますが、パス属性の述語を使用してレコードをフェッチしようとすると、例外がスローされます。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the
 format string "filePath==/Users/****/Library/Application Support/iPhone Simulator/5.1/Applications
/8C1B07FD-E372-4CD8-9A02-FDA321ECE629/Documents"'

属性はCoreDataDBに適切に保存されます。

取得するコード。

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    fetchRequest.predicate=[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"filePath==%@",Path]];
    NSSortDescriptor *sortDescriptor=[NSSortDescriptor sortDescriptorWithKey:@"fileName" ascending:YES];
    fetchRequest.sortDescriptors=[NSArray arrayWithObject:sortDescriptor];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"File"
                                              inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

    NSArray *fetchedObjects = [self.managedObjectContext
                               executeFetchRequest:fetchRequest error:nil
                               ];
4

2 に答える 2

1

ファイルパスに、適切な解析を妨げる空白などの文字が含まれている可能性があります。これを試して:

[NSPredicate predicateWithFormat:@"filePath = '%@'", path]; 
于 2013-03-08T11:37:18.080 に答える
1

NSPredicateクラスリファレンスの例では、文字列に二重引用符を使用しています。

Simple comparisons, such as grade == "7" or firstName like "Shaffiq"

示されているエラーには、引用符のない述語が含まれています-おそらく問題の原因ですか?

于 2013-03-08T13:41:53.923 に答える