Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current user's home directory

I'm developing a Cocoa Objective-C application that will run on Mac OS X. I need to get the full path of the current user's home directory:

/Users/MyUser/

Is there a standard function that does that in Objective-C/Cocoa?

like image 261
sashoalm Avatar asked Aug 05 '11 15:08

sashoalm


2 Answers

NSHomeDirectory: “Returns the path to the current user’s home directory.”

Example:

NSLog(@"Current user’s home directory is %@", NSHomeDirectory());
like image 97
zoul Avatar answered Sep 26 '22 11:09

zoul


Since macOS 10.12 you can also use FileManager.default.homeDirectoryForCurrentUser, see the documentation.

like image 30
just_a_guy Avatar answered Sep 26 '22 11:09

just_a_guy