Iphone iCloud:获取云中存在的文件数组

Iphone iCloud:获取云中存在的文件数组,iphone,cocoa-touch,metadata,ios5,icloud,Iphone,Cocoa Touch,Metadata,Ios5,Icloud,我想获得一个用户iCloud帐户中存储的所有txt文件的列表。检查iCloud是否已启用后,我尝试了以下操作: NSMetadataQuery *query = [[NSMetadataQuery alloc] init]; _query = query; [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; NSPr

我想获得一个用户iCloud帐户中存储的所有txt文件的列表。检查iCloud是否已启用后,我尝试了以下操作:

NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
        _query = query;
        [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; 

        NSPredicate *pred = [NSPredicate predicateWithFormat:@"self ENDSWITH '.txt'"];
        [query setPredicate:pred];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:query];
        [query startQuery];
但我得到了以下控制台输出和崩溃:

    2011-10-23 21:58:19.587 iCloudText[9922:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSComparisonPredicate with left expression which is not NSKeyPathExpressionType given to NSMetadataQuery (SELF ENDSWITH ".txt")'
*** First throw call stack:
(0x30ef58bf 0x3809a1e5 0x30ef57b9 0x30ef57db 0x37f4e725 0x37f4b0b5 0x29b3 0x2c4b 0x32ec77eb 0x32ec13bd 0x32e8f921 0x32e8f3bf 0x32e8ed2d 0x33a7ae13 0x30ec9553 0x30ec94f5 0x30ec8343 0x30e4b4dd 0x30e4b3a5 0x32ec0457 0x32ebd743 0x2437 0x23dc)
terminate called throwing an exception(gdb) 

定义谓词时我做错了什么?我读过文件,但不知道哪里出了错。任何帮助都将不胜感激

尝试使用
[NSPredicate predicateWithFormat:@“%K ENDSWITH”.txt”,NSMetadataItemFSNameKey]
作为谓词
SELF
在本例中不引用文件名。

谢谢!工作得很好。我知道这是另一个问题,但我如何才能只获取文件夹列表?我是否会使用%K ISDIRECTORY或类似的工具?谢谢