For a project I needed to validate a 13 digit ISBN. According to Wikipedia you can validate an ISBN by calculating the checksum, but more accurately calculating the check-digit of an ISBN as follows: The ISBN-13 check digit, which is the last digit of the ISBN, must range from 0 to 9 and must be […]
Swift 4: An extension to define UIColors with “normal” RGB values and set some named colors
UIColors require you to enter red, green and blue as values between 0 and 1. In pracitcal terms that means you need to divide your values by 255 to obtain the CGFloat required. Easy enough? Surely! Still it is a tad annoying, especially as the rest of the world will give you RGB values between […]
Swift 4: Pull To Refresh / UIRefreshControl
TableViews can have a useful feature to refresh the data inside of them, simply pull to refresh. Apple didn’t invent this, that was Loren Brichter of Tweetie, which was sold to Twitter and Twitter was eventually granted a Patent for the feature. Today this feature is absolutely ambiguous and very easy to implement. For example, […]
Swift 4: JSON decoding with JSONDecoder() and structs
I have no apps in the app store, but a while ago I wrote an app for my own edutainment, which needed to parse JSON Data. At the time it was so darn complicated, that I enlisted Cocoapods and SwiftyJSON to help make things easier. SwiftJSON is pretty cool as it abstracts away a lot […]
Swift 4: scale image to width
For an app that I was writing I needed an easy function to scale an image to a specific width, the function below will accomplish this: func scaleImageWidth(sourceImage:UIImage, scaledToWidth: CGFloat) -> UIImage { let oldWidth = sourceImage.size.width let scaleFactor = scaledToWidth / oldWidth let newHeight = sourceImage.size.height * scaleFactor let newWidth = oldWidth * scaleFactor […]
Swift 4: Image from Core Data upside down
I have a few days off and was having a play with creating a very simple app. The app basically allows you to take a photo, add a description and saves all of it to Core Data. Unfortunately Core Data cannot save images the way they are, so you first need to convert them to […]