Learning Swift - Sets
Sets are the forgotten collection type in many languages, including Swift. I think most developers use Arrays without really considering the advantages of using a Set but they have some amazingly useful features that should make them a part of any programmer’s toolkit.
If you want to follow along with a playground, you can download it here .
What is a Set? # A Set is an un-ordered collection of unique items.
19th Hole Golf Scorer 3.1
One of the problems with using 19th Hole on the Apple Watch is making the app show every time you raise your wrist. My solution to this was to go into Settings (either on my iPhone through the Watch app, or directly on the watch) and change it to “Resume Last Activity” on wrist raise. This worked fine but as I usually prefer the watch face to show on wrist raise, I had to keep setting and re-setting this which was a pain.
My Year With Apple Watch
As the Apple Watch hits its first birthday, there seems to be in increasing number of bloggers complaining about it. One (which I refuse to link to) titled “My Year of Hell With the Apple Watch”. I think the article has since been re-published with a slightly less inflammatory title, but really! Did somebody rivet the watch to his wrist? If it was so awful, why not just stop using it?
How To Confuse TestFlight
I ran into an unusual problem when testing my latest app: “What Is My Speed? ”. It is now available from the iTunes App Store , but getting there was a struggle.
Road Trip Apps
Over the past few months, we have done two long road trips: one approximately 4,000 km and the other about 1,800 km. These gave us the chance to try out various apps for navigation and travel information. We live in Queensland, Australia and some of these comments may be country-specific.
Navigation # The basic navigation came down to three apps:
Apple Maps Google Maps Metroview (Australia and New Zealand only) Each has their strengths and weaknesses:
Structs vs Classes
One of the big debates among Swift developers is when to use structs and when to use classes.
Classes are the building blocks of object-oriented programming but structs as provided by Swift are newly powerful. Structs have been around in C-based languages for a long time, but Swift has made them more powerful and given them more features so that they are almost indistinguishable from classes. So what are the differences and which one should you use?
Learning Swift - For-Loops
Loops are a fundamental building block of any program. Doing repetitive tasks fast and accurately is what computers are really good at and what we humans get very bored doing. Swift offers several different ways to perform loops, but today we are going to concentrate on for-loops.
The most basic form of loop is the for-in loop. There are two ways this can be used: looping over the numbers in a range or looping over the elements in an array or dictionary.
Learning Swift - Generics
One of the nice things about Swift is how clean your code looks. A lot of the weird characters that pepper the code of other languages has been eliminated: No more semi-colons, asterisks etc.
But then you are reading somebody else’s code and you find these angle brackets all over the place and they don’t seem to make sense.
What does this mean?
func mid<T: Comparable>(array: [T]) -> T It looks like it is a function to find the middle element in an array, but what is <T: Comparable> or [T] or even just T?
Singleton to Protocol
I was driving through the town of Singleton the other day and of course, it got me thinking about using singletons in my apps. Singletons were a commonly used pattern in Objective-C programming and appear in many of Apple’s own APIs, but seem to be increasingly frowned upon in the Swift world.
So what is a singleton? # A singleton is a class that only expects to have a single instance.