Swift – Login Name of Current User

To get login name of current logon user in Swift, call NSUserName() function.

The following code snippet returns the String representing the login name of the current logon user.

</>
Copy
NSUserName()

Example

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

main.swift

</>
Copy
import Foundation

let username = NSUserName()
print(username)

Output

tutorialkart

Conclusion

In this Swift Tutorial, we learned how to get the name of current logon user.