Database Reference
In-Depth Information
[fileURL getResourceValue:&aBool forKey:NSURLIsHiddenKey error:nil];
if(aBool && ![aBool boolValue]){
[_iCloudURLs addObject:fileURL];
}
}];
NSLog(@"Found %i files in iCloud",[_iCloudURLs count]);
_iCloudIsReady = YES;
if([self iCloudOn]){
for(NSInteger i = [_entries count] - 1; i >= 0; i--){
CTEntry *entry = _entries[i];
if(![_iCloudURLs containsObject:[entry fileURL]]){
[self removeEntryWithURL:[entry fileURL]];
}
}
[_iCloudURLs enumerateObjectsUsingBlock:^(NSURL *fileURL, NSUInteger idx, BOOL *stop) {
[self loadDocumentAtFileURL:fileURL];
}];
[self.navigationItem.rightBarButtonItem setEnabled:YES];
}
[_query enableUpdates];
if(_awaitingMoveLocalToiCloud) {
_awaitingMoveLocalToiCloud = NO;
//TODO #1 move data to iCloud
} else if(_awaitingCopyiCloudToLocal){
//TODO #2 copy data from iCloud
}
}
We start off by calling disableUpdates on our NSMetadataQuery object. We do this because our result
set could change. Calling disableUpdates makes sure that the data set we are going to enumerate
over is not going to change on us. We follow this up by clearing our iCloudURLs array because we
will be enumerating over all files and not just new ones.
Next we use the enumerateObjectsUsingBlock : method on the results array inside our
NSMetadataQuery object. It holds an array of NSMetadataItems . Inside this block we start by getting
the NSURL for the file by calling valueForAttribute and passing it the NSMetadataItemURLKey key.
We then create an NSNumber object called aBool and set it to nil .
Next we check to see if this is a hidden file by calling the method getResourceValue:forKey:error
method on the NSURL object fileURL. We pass the pointer of our NSNumber aBool and the key
NSURLIsHiddenKey. Then we check to see if aBool is not nil and if it is set to NO which means the
file is not a hidden file. If this statement is true we add the fileURL object to our iCloudURLs array.
Search WWH ::




Custom Search