How to get the user "Name" using Swift?

ios, swift

Solution

UIDevice.current.name gives back device name, so you should parse the string trying to distinguish between device type (iPhone, iPad and so on...) and the name. But is bit tricky: suppose You have "My iPhone" , "Mary's iPhone" or "IPhone of John" or similar.

Soem people try to use regular expressions, but result is not so good, specially for non-english names. see at:

http://stackoverflow.com/questions/8261961/better-way-to-get-the-users-name-from-device

Problem

I'm trying to create an app that when the user open the first view it will provide with a nice greeting. For example depending on the time of the day it would say "Good Morning/Afternoon/Night - User Name". How do I get the name that the User has on his iPhone? I need the name that is on `Settings > General > About _ NAME`?

Original source

Related problems