Zbun
Zbun

Reputation: 4945

Create file with specific permisions in iOS

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

Upvotes: 1

Views: 604

Answers (1)

trojanfoe
trojanfoe

Reputation: 122458

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.

Upvotes: 1

Related Questions