converted first chapter 16 example to Swift