title: Objective c cannot write file to directory permission issue
body: <p>I need to save some image on directory which is created by the app, here is the code to create the directory and set full permission</p>
  
  <pre><code>NSFileManager* manager = [NSFileManager defaultManager];
  SnapDir = [AssetPath stringByAppendingPathComponent:@"ScreenCaptures"];
  if (![manager fileExistsAtPath:AssetWatchSnapDir isDirectory:&amp;isDirectory] || !isDirectory)
  {
      NSError *error = nil;
  
      [manager createDirectoryAtPath:SnapDir
                   withIntermediateDirectories:NO
                   attributes:nil
                   error:&amp;error];
      if (error)
          NSLog(@"Error creating directory snap path: %@", [error localizedDescription]);
      else {
          NSError *error1;
          [manager setAttributes:@{ NSFilePosixPermissions : @0777 }
                       ofItemAtPath:SnapDir error:&amp;error1];
      }
  }
  
  [[NSUserDefaults standardUserDefaults] setObject:SnapDir forKey:@"AssetSnap"];
  </code></pre>
  
  <p>Now I have saving the image png like,</p>
  
  <pre><code>SnapDir = [[NSUserDefaults standardUserDefaults] objectForKey:@"AssetSnap"];  
  NSString* filepath = [SnapDir stringByAppendingPathComponent:filename];
  NSError *error;
  bool success = [pngRep writeToFile:filepath options:0 error:&amp;error];
  if (!success) {
      NSLog(@"writeToFile failed with error %@", error);
  }
  </code></pre>
  
  <p>This works fine when if the image save happen at the same instance of app run of  directory creation. That is I open application, created directory by the application and then save.  </p>
  
  <p>Where as when close the application and open it again and try to save the image(using the destination path stored at <code>NSUserDefaults</code>), it gives the following error regarding permission issue. </p>
  
  <pre><code>Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “2016_08_19_06_32_00.png” in the folder “ScreenCaptures”." UserInfo={NSFilePath=/Users/development/Documents/d/ScreenCaptures/
  </code></pre>