简体   繁体   中英

IOS NSPredicate Not Working

The following example program: although the same url it can not find the url, but the program does not work correctly.

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");
    }
}

Outputs:

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

does not work correctly when special characters in url. Why is this happening? Thanks ...

The HFS file system uses "decomposite characters", eg é in a file name is stored as two characters e + ´ (U+0301, COMBINING ACUTE ACCENT). Normalizing the file names from the directory enumeration using precomposedStringWithCanonicalMapping should help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM