Swift (iOS) – Extensions


I’ve been doing some Swift iOS training through Team Tree House. It’s been very fun to learn this new, exciting, powerful language for developing native applications for iOS, macOS, watchOS, and tvOS. I had a code challenge where I needed to create an extension to the String class. Basically it’s creating a new method/function called “add” where you pass it an integer value. If the string can be converted into an integer then take the integer parameter and add it to the value of the string. For example “1”.add(value: 2) would return an integer of 3. If you tried “h”.add(value: 3) then it would return “nil.” It was a nice little challenge and something that had to be thought through. Here is a screenshot of my XCode Playground –