2011-10-23 2 views
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) 

술어를 정의 할 때 내가 잘못 뭐하는 거지? 나는 문서를 읽었으나 어디서 잘못되었는지 알 수 없다. 어떤 도움이라도 대단히 감사하게 될 것입니다!

답변

2

[NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey]을 귀하의 조건 자로 사용해보십시오. SELF은이 경우 파일 이름을 참조하지 않습니다.

+0

감사합니다. 완벽하게 일했습니다. 나는 이것이 또 다른 질문이라는 것을 알고 있지만 폴더 목록 만 얻으려면 어떻게해야합니까? % K ISDIRECTORY 또는 그 라인을 따라 작업 할 수 있습니까? 감사. –

관련 문제