A few years ago, Apple's Swift team posted an interesting article titled Increasing Performance by Reducing Dynamic Dispatch. It's a very interesting read, highlighting some of the more subtle aspects of the Swift language and its compiler.
Object literals are very useful and they often make your code easier to read and understand. String literals are a bit different, though. It's true that a string literal is the easiest solution to create a
String instance. It's straightforward and everyone understands what's going on. But there's a price you pay every time you use a string literal. Did you know that?
In today's tutorial, I'd like to show you an elegant example of the power and versatility of generics and protocols. I stumbled upon this implementation while browsing the RxDataSources repository a few months ago. I learned the technique I outline in this tutorial from Segii Shulga. Let me show you what it looks like.
Fatal errors have a negative connotation and with reason. You should use them sparingly if you want to avoid having your application crash and burn at the slightest hiccup. Despite their negative undertone, fatal errors are an integral part of my workflow as I write elsewhere in this book.
Many developers new to Swift seem to be struggling with JSON. Despite the speed of Foundation's
JSONSerialization class, it hands you an object of type
Any, leaving it up to you to unwrap the object you received.
Last year, I wrote about the difference between
fileprivate in Swift 3. With the impending release of Swift 4, it's time for an update. Access control underwent several important changes since the introduction of the Swift language, several years ago.
Last week, I wrote about weak and strong outlets. But there's another question about outlets that comes up frequently. Should outlets be declared as optionals or implicitly unwrapped optionals? This tutorial zooms in on the pros and cons of each of these options.
A surprising number of developers struggle with bitmasks and bitwise operations. If you've had problems working with bitmasks, then I have good news for you. Swift's standard library makes this easy. In this tutorial, I'd like to walk you through an example I worked on last week for an application I'm working on.