XDR
XDR

Reputation: 4470

API available to Swift that provides the Apple ID associated with the current macOS user?

Is there any API available to Swift that provides the name (which should be an email address, AFAIK) of the Apple ID associated with the current macOS user?

The following command line seems to provide the correct info, but I'd prefer not to have to run a separate Process to get this info in my Swift code:

defaults read MobileMeAccounts | plutil -extract "Accounts".0."AccountID" raw -o - -

Thanks.

Upvotes: 0

Views: 110

Answers (1)

XDR
XDR

Reputation: 4470

Found the answer myself:

(UserDefaults.standard.persistentDomain(forName: "MobileMeAccounts")?["Accounts"] as? [[String: Any]])?.first?["AccountID"]

If anyone knows a more concise answer, please let me know.

Upvotes: 0

Related Questions