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

发布于 2024-12-11 06:14:16 字数 1274 浏览 0 评论 0原文

我想获取用户 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) 

定义谓词时我做错了什么?我已阅读文档,但无法弄清楚我错在哪里。任何帮助将非常感激!

I'd like to get a list of all txt files stored in a user's iCloud account. After checking if iCloud is enabled, I tried the following:

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];

But I get the following console output and a crash:

    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) 

What am I doing wrong when defining the predicate? I've read the docs but can't figure out where I went wrong. Any help would be very much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡大本事 2024-12-18 06:14:16

尝试使用 [NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey] 作为谓词。在这种情况下,SELF 并不引用文件名。

Try using [NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey] as your predicate. SELF doesn't refer to the filename in this case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文