0

I am trying to use the BoxSDK on iOS, and I need to load the parent directory of the current folder/file. I have an array of BoxItems, and I try to get the BoxItem.parent and it is always null. The same goes for the pathCollection.

When the app loads, I load the last directory using the ModelID and name. How do I get the parent directory of this BoxItem?

EDIT: I think I am getting a bunch of BoxModels back from my request. How do I get BoxItems that carry the ParentID back?

Here is my code:

- (void)fetchFolderItemsWithFolderID:(NSString *)folderID name:(NSString *)name
{
    _folderListArray = [[NSMutableArray alloc]init];
    BoxCollectionBlock success = ^(BoxCollection *collection)
    {
        //_folderListArray = [[NSMutableArray alloc]init];
        for (NSUInteger i = 0; i < collection.numberOfEntries; i++)
        {
            [_folderListArray addObject:[collection modelAtIndex:i]];
        }
        dispatch_sync(dispatch_get_main_queue(), ^{
            [self fetchFolderInfoWithID:folderID];
            [self.tableView reloadData];
            [self.refreshControl endRefreshing];
        });
    };
    BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
    {
        NSLog(@"folder items error: %@", error);
    };
    [[BoxSDK sharedSDK].foldersManager folderItemsWithID:folderID requestBuilder:nil success:success failure:failure];

and I get a BoxCollection full of BoxItems that I can use to load my tableView. This is out of the sample apps.

Then I want to get the parent of that folderID that I just got the BoxItems from, so I use this:

- (void)fetchFolderInfoWithID:(NSString *)folderID
{
    BoxFolderBlock success = ^(BoxFolder *folder)
    {
        //trying to print parent
        NSLog(@"Parent: %@", folder.pathCollection);
    NSLog(@"Parent: %@", folder.parent);
        dispatch_sync(dispatch_get_main_queue(), ^{
            NSLog(@"Parent: %@", folder.parent);
        });
    };
    BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
    {
        NSLog(@"folder items error: %@", error);
    };
    BoxFoldersRequestBuilder *itemBldr = [[BoxFoldersRequestBuilder alloc]initWithQueryStringParameters:@{ @"fields" : @"name,type,id,size,modified_at,created_by,parent,path_collection" }];
    [[BoxSDK sharedSDK].foldersManager folderInfoWithID:folderID requestBuilder:itemBldr success:success failure:failure];
}
Siriss
  • 3,737
  • 4
  • 32
  • 65

1 Answers1

0

So I finally figured it out. I am getting a bunch of BoxItems back from the Box query. Now the documentation says that the BoxItem has a parent method, but to get it, you need to create a BoxFolder object and set it equal to the BoxItem.parent.

BoxItem *item = <item returned from query>;
BoxFolder *folder = item.parent;
NSString *paretnModelID = folder.modalID;

This will get you the parent object to reference.

Siriss
  • 3,737
  • 4
  • 32
  • 65