converted first example from chapter 21 to swift