Added code and tested. There is something wrong with the Swift solution but I can't see it.