2016-11-30 1 views
0

NSMetadataQuery 클래스는 Finder/Spotlight가 메타 데이터를 통해 파일을 검색하는 방법 인 것 같습니다. Spotlight 파일 메타 데이터 속성/NSMetadataQuery에 의해 파일 URL의 NSArray를 필터링하는 방법?

https://developer.apple.com/library/content/documentation/Carbon/Conceptual/SpotlightQuery/Concepts/Introduction.html#//apple_ref/doc/uid/TP40001843-BBCFBCAG

NSMetadataQuery class provided by the Foundation framework. Queries can be run in two modes: asynchronous, and asynchronous with live updates. The first simply performs the search on the files that exist at the time of the initial search. The latter continues to search. updating the data as the files that fulfill or no longer fulfill the search parameters update.

는 그러나, 디렉토리 ( searchScopes)를 제공 주위 지향하고, 해당 디렉토리 ( NSMetadataQueryDidFinishGathering)에서 발견되었다 다음 비동기 적으로 결과를 리턴 보인다.

이미 NSArray에 파일 URL이 있습니다. Spotlight Search와 동일한 메타 데이터 및 쿼리 구문을 사용하여 해당 NSURL의 필터/검색을 만들고 싶습니다. 하지만 디렉토리를 제공하고 비동기 결과를받는 대신 파일 목록을 신속하게 제공합니다. 즉, 표준 자 NSPredicate 검색이 아닌 파일 메타 데이터 필터를 사용하고 오류를 던지고있다 그러나

// Something like this... 
let imageFileTypePredicate = NSPredicate(fromMetadataQueryString: "(kMDItemGroupId = 13)") 
let imageURLs = allURLs.filter{ imageFileTypePredicate.evaluate(with:$0) }; 

:

this class is not key value coding-compliant for the key _kMDItemGroupId.

메타 데이터가 나는 다음과 같습니다에 의해 필터링에 관심이 속성 스포트 라이트 :
https://developer.apple.com/library/content/documentation/CoreServices/Reference/MetadataAttributesRef/Reference/CommonAttrs.html#//apple_ref/doc/uid/TP40001694-SW1

어떻게 파일 URL 배열을 Spotlight 메타 데이터로 필터링 할 수 있습니까?

답변

0

각 URL에 대해 파일의 스포트라이트 속성을 가져 오는 MDItem을 만듭니다.

MDItem is a CF-compliant object that represents a file and the metadata associated with the file.

https://developer.apple.com/reference/coreservices/1658213-mditem

MDItemRef item = MDItemCreateWithURL(kCFAllocatorDefault, url); 
CFArrayRef attributes = MDItemCopyAttributeNames(item); 
NSDictionary *attributeValues = CFBridgingRelease(MDItemCopyAttributes(item, attributes)); 
관련 문제