1

In my project i'm creating a file using the function:

- (BOOL)createFileAtPath:(NSString *)path contents:(NSData *)data attributes:(NSDictionary *)attr;

I want to grant this file permissions so only the user can read and write (-rw------). I cant figure out (or find documentation) how i should fill this attribute dictionary (keys and values).

Thanks in advance

Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35
Zbun
  • 4,875
  • 4
  • 19
  • 28
  • Who are you protecting the file from? – trojanfoe Jul 24 '14 at 09:23
  • I am building SDK and i want it to be the only one who reads and write to a specific file. don't want other to be able to do it – Zbun Jul 24 '14 at 09:25
  • https://www.google.co.in/search?client=safari&rls=en&q=protect+the+file+ios&ie=UTF-8&oe=UTF-8&gfe_rd=cr&ei=udHQU7uREIbV8geoi4GwCA – Arun Jul 24 '14 at 09:30

1 Answers1

1

It's not clear what you expect to gain from this, but the syntax is:

NSDictionary *attributes = @{
    NSFilePosixPermissions : @((short)(0x600))
};
BOOL created = [[NSFileManager defaultManager] createFileAtPath:path
                                                       contents:data
                                                     attributes:attributes];

Not sure if you actually need the (short) cast or not.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • It's not that important, but i still want to play it on the safe side. can you tell me where can you find documentation for it? Thanks! – Zbun Jul 24 '14 at 09:29
  • https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/nsfilemanager_class/reference/reference.html#//apple_ref/occ/instm/NSFileManager/createFileAtPath:contents:attributes: – trojanfoe Jul 24 '14 at 09:29
  • Shouldn't the value be `0600`, not `0x600`? You want the octal value `600`, not the hex value `600`. There's a big difference. – rmaddy Jan 30 '15 at 16:20