Database Reference
In-Depth Information
If it does then nameExists is set to true and we break the while loop and return this new document
name. If it does exist, we loop again, but this time adding a counter to the end of the filename. The
same check is done until we find a unique name.
Now let's add the documentNameExistsInObjects : method:
-(BOOL)documentNameExistsInObjects:(NSString *)documentName {
__block BOOL nameExists = NO;
[_entries enumerateObjectsUsingBlock:^(CTEntry *entry, NSUInteger idx, BOOL *stop) {
if([[[entry fileURL] lastPathComponent] isEqualToString:documentName]){
nameExists = YES;
*stop = YES;
}
}];
return nameExists;
}
In this method we do a simple enumeration over our entries array and check the
lastPathComponent(filename) and determine if any of them are equal to our passed in document
name. If they are, we set the BOOL value for nameExists to YES and exit the enumeration. We return
our BOOL value to let the receiver know our results.
The last thing we need to do in this file is modify our EntryCollectionViewCellDelegate method to
take in a CTEntry instead of an NSString . We will modify the EntryCollectionViewCell next.
-(void)entryCollectionViewCell:(EntryCollectionViewCell *)cell longPressedForEntry:(CTEntry *)entry {
Now we need to go back and modify our EntryCollectionViewCell to handle our CTEntry object
instead of the generic NSString we were using before. Open up the EntryCollectionViewCell.h file.
We need to add the class declaration for CTEntry above our first protocol statement.
@class CTEntry;
Next we need to change the entry type in our configureCellForEntry:withDelegate method to use a
CTEntry instead of NSString .
-(void)configureCellForEntry:(CTEntry *)entry
withDelegate:(id<EntryCollectionViewCellDelegate>)delegate;
The last change we need to make to this header file is to change the delegate method's final
parameter from an NSString to a CTEntry .
-(void)entryCollectionViewCell:(EntryCollectionViewCell *)cell longPressedForEntry:(CTEntry *)entry;
Moving over to the EntryCollectionViewCell.m file we need to add an import statement for
CTEntry.h and CTMetadata.h .
#import "CTEntry.h"
#import "CTMetadata.h"
 
Search WWH ::




Custom Search