You could use UUID
var uuid = UUID(uuidString: yourString)
This will return nil if yourString
is not a valid UUID
Note: this only validates the first case you presented, not the second but adding the dashes yourself is trivial.
You could use UUID
var uuid = UUID(uuidString: yourString)
This will return nil if yourString
is not a valid UUID
Note: this only validates the first case you presented, not the second but adding the dashes yourself is trivial.