Swift – Home Directory for Current User

To get home directory for current user in Swift, read homeDirectoryForCurrentUser property of shared file manager object for the process.

The following code snippet returns the home directory of the current user.

FileManager.default.homeDirectoryForCurrentUser

Example

In the following example Swift program, we will get the home directory of the current user, using the code snippet mentioned above.

main.swift

import Foundation

let home = FileManager.default.homeDirectoryForCurrentUser
print(home)

Output

file:///Users/tutorialkart/
ADVERTISEMENT

Conclusion

In this Swift Tutorial, we learned how to get the path to home directory of current user.