converted next chapter 16 example to Swift