Catalyst document folder does not exist

Hey, on iOS we always access the document folder assuming it exists, but on Catalyst we ran into issues caused by the fact that the document folder does not exist, so we had to create it first. Is it normal behaviour on catalyst ?

Accepted Reply

Yes, it’s normal. You can use FileManager.url(for:in:appropriateFor:create:) to look up this directory, and pass true to the create: parameter to get this directory created for you if needed.
  • This worked for me:

    NSFileManager *fileManager = [NSFileManager defaultManager];

        NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];

        NSArray *urls = [fileManager contentsOfDirectoryAtURL:directoryURL includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLNameKey, NSURLIsDirectoryKey, NSURLContentModificationDateKey, nil] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];

        NSLog(@"%@",urls);

Add a Comment

Replies

Yes, it’s normal. You can use FileManager.url(for:in:appropriateFor:create:) to look up this directory, and pass true to the create: parameter to get this directory created for you if needed.
  • This worked for me:

    NSFileManager *fileManager = [NSFileManager defaultManager];

        NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];

        NSArray *urls = [fileManager contentsOfDirectoryAtURL:directoryURL includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLNameKey, NSURLIsDirectoryKey, NSURLContentModificationDateKey, nil] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];

        NSLog(@"%@",urls);

Add a Comment

This worked for me:
NSFileManager *fileManager = [NSFileManager defaultManager];     NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];