Question

There is an iOS sample project for the Dropbox Datastore API available here: https://www.dropbox.com/developers/datastore/sdks/ios

Inside that project's main class (TasksController.m), it has some API-related properties:

@property (nonatomic, readonly) DBAccountManager *accountManager;
@property (nonatomic, readonly) DBAccount *account;
@property (nonatomic, retain) DBDatastore *store;

...as well as some private methods:

- (DBAccountManager *)accountManager {
    return [DBAccountManager sharedManager];
}

- (DBAccount *)account {
    return self.accountManager.linkedAccount;
}

- (DBDatastore *)store {
    if (!_store && self.account) {
        _store = [DBDatastore openDefaultStoreForAccount:self.account error:nil];
    }
    return _store;
}

There aren't any code comments describing these. Why is this class structured this way? Do all classes working with the API need to use a similar structure?

For example, can I just declare DBAccount *account in viewDidLoad or should I be using the read-only property somehow?

Was it helpful?

Solution

I guess it depends on what scope you want. If you don't need the DBAcccount outside of viewDidLoad, then feel free to just declare it there. For the DBDatastore, however, you need to make sure it stays in scope for the lifetime of your app (or at least as long as you care about it syncing with Dropbox). As soon as it goes out of scope, it will also stop syncing changes to and from the server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top