Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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

share|improve this question
    
Who are you protecting the file from? –  trojanfoe Jul 24 '14 at 9: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 9:25
    
google.co.in/… –  Spynet Jul 24 '14 at 9:30

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 9: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 at 16:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.