2011-10-23 3 views
0

ユーザーのiCloudアカウントに保存されているすべてのtxtファイルのリストを取得したいと考えています。 iCloudのが有効になっているかどうかをチェックした後、私が試した次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) 

述語を定義するときに私が間違っているのか?私はドキュメントを読んだが、どこが間違っているのか分からない。どんな助けも非常に高く評価されるでしょう!

答えて

2

[NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey]をあなたのプレディケートとして使用してください。 SELFはこの場合ファイル名を参照しません。

+0

ありがとうございます!完璧に働いた。私はこれが別の問題だと知っていますが、フォルダのリストだけを取得するにはどうすればいいですか?私は%K ISDIRECTORYやそれらの行に沿った何かで動作しますか?ありがとう。 –

関連する問題