Objective C
The name I was looking for is:
[[NSHost currentHost] localizedName];
It returns “Jonathan’s MacBook” rather than “Jonathans-Macbook”, or “jonathans-macbook.local” which just name returns.
Swift 3
For Swift >= 3 use.
if let deviceName = Host.current().localizedName {
print(deviceName)
}