converted chapter 11 example to swift