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?
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:
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?
Today I plan to discuss optionals since they were a feature of Swift that I found difficult to grasp at first. What is an optional in Swift? An optional is a variable of a specified type that can also be nil. Why does this matter? In Objective-C, any object type could be nil. If you declared a variable like this: NSString *myString; then myString was set to nil by default.
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.
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?
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.
- Do not use !.
- Use let, not var.
- Allow the compiler to infer types.
Read on for more details…
While not strictly a part of my Learning Swift series, today I thought I would discuss some of the ways to configure and use Xcode to be a more productive and comfortable programmer. 1. Editor color themes and fonts: Step through the supplied themes and find the best one for you. Then click the ‘+’ button at the bottom of the list and duplicate the selected theme. Now you can tweak it to suit you.