以下示例程序:虽然相同的url它找不到url,但程序无法正常工作。
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:kDocdir];
for (NSString *pathi in directoryEnumerator)
{
NSLog(@"fileManager_url = %@",[self Doc_Del:pathi]);
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"url == %@",[self Doc_Del:pathi]];
[fetchRequest setPredicate:predicate];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:nil];
Artist *url_Databse = [self.fetchedResultsController objectAtIndexPath:self.indexPath_k];
NSLog(@"Database_url = %@",url_Databse.url);
if ([fetchedObjects count] > 0) {
NSLog(@"foundurl = %@",((Artist *)[fetchedObjects objectAtIndex:0]).url);
}else{
NSLog(@"url not found");
}
}
输出:
2013-04-25 15:37:43.256 Player[36436:907] fileManager_url = /alizée -öş mèxico - final j'en
2013-04-25 15:37:43.272 Player[36436:907] Database_url = /alizée -öş mèxico - final j'en
2013-04-25 15:37:44.107 Player[36436:907] url not found
当url中的特殊字符时,无法正常工作。为什么会这样?谢谢......
答案 0 :(得分:0)
HFS文件系统使用“decomposite characters”,例如文件名中的é
存储为两个字符e
+ ´
(U + 0301,COMBINING ACUTE ACCENT)。使用precomposedStringWithCanonicalMapping
从目录枚举中规范化文件名应该会有所帮助。