Database Reference
In-Depth Information
Next we call
saveToURL:forSaveOperation:completionHandler
: on our document object. We
then create a metadata object and assign the contents of our document's metadata to it. Then
we create three more objects for
fileURL
, state, and version. I'm sure this looks familiar. Next
we set our
selectedDocument
to the document we just created. Then we add a
dispatch_async
block to execute the next two calls on the main thread. The first method call we make is to
ad
dOrUpdateEntryWithURL:metadata:state:version,
which creates a
CTEntry
for this document.
Then we call
performSeguqWithIdentifier
and pass it “ToFriendDetails”, which moves us to our
FriendDetailViewController
.
Now we can add those two methods that we referenced earlier.
-(NSURL *)getDocmentURL:(NSString *)filename {
return [[AppDelegate applicationDocumentsDirectory] URLByAppendingPathComponent:filename
isDirectory:NO];
}
-(NSString *)getDocumentFilename:(NSString *)filename forLocal:(BOOL)isLocal {
NSInteger docCount = 0;
NSString *newDocName = nil;
BOOL done = NO;
BOOL first = YES;
while(!done){
if(first){
first = NO;
newDocName = [NSString stringWithFormat:@"%@.%@",filename,CT_EXTENSION];
} else {
newDocName = [NSString stringWithFormat:@"%@_%d.%@",filename,docCount,CT_EXTENSION];
}
BOOL nameExists = NO;
if(isLocal){
nameExists = [self documentNameExistsInObjects:newDocName];
}
if(!nameExists){
break;
} else {
docCount++;
}
}
return newDocName;
}
The first method
getDocumentURL
: currently just returns us the URL for the application documents
directory. This method is more useful when we start integrating iCloud.
The second method is
getDocumentFilename
:
forLocal
:. The majority of the code in this method
is within the
while
loop. The first time through the
while
loop we create the document name by
using the passed in
NSString
parameter and adding our file extension to it. We then check to see
if the name exists by calling the
documentNameExistsInObjects:
method. We will write this shortly.
Search WWH ::
Custom Search