converted chapter 20 example to swift