converted last chapter 22 example to swift