Sunday, 11 August 2013

working with delegates synchronously -objective-c

working with delegates synchronously -objective-c

In the below code, self.theFiles prints the null. Because after calling
[self.restClient loadMetadata:@"/"], "getFiles method" is keeping working.
I want 'getFiles method' to wait until [self.restClient loadMetadata:@"/"]
finish to get file list and put the data to self.theFiles object. But
after [self.restClient loadMetadata:@"/"], "getFiles" is keeping working.
@synthesize theFiles;
- (void)getFiles:(CDVInvokedUrlCommand*)command
{
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] linkFromController:self];
}
else
{
[self.restClient loadMetadata:@"/"];
}
NSLog(self.theFiles); //Prints null
NSLog(@"Finished");
}
#pragma mark DBRestClientDelegate methods
- (void)restClient:(DBRestClient*)client
loadedMetadata:(DBMetadata*)metadata {
NSArray* validExtensions = [NSArray arrayWithObjects:@"txt", @"text",
nil];
NSMutableArray* newPhotoPaths = [NSMutableArray new];
for (DBMetadata* child in metadata.contents) {
self.theFiles=child.path;
NSString* extension = [[child.path pathExtension] lowercaseString];
if (!child.isDirectory && [validExtensions
indexOfObject:extension] != NSNotFound) {
[newPhotoPaths addObject:child.path];
}
}
NSLog(self.theFiles); //Prints the file list
}
Output:
null
Finished
/file1.txt
/file2.txt
..... the file list in my dropbox
Is it possible to work my getFiles method with delegate synchronously?

No comments:

Post a Comment