Tag: swift
-
Segue Actions
If you’ve been working with View controllers for a while, you’ve probably dealt with prepareForSegue. In Xcode 11, there’s a new way to handle this that makes a little more sense: Segue actions. Let’s take a look at this feature. If you download the storyboard, you’ll find I set one up for you. It is…
-
Use Sets in Swift
Of the most underrated collection types is sets. Sets are an unordered collection with unique values. Let’s take a look at what you can do with sets. Download the exercise files and you’ll find I created playground with a Struct called Pizza. I’ve made two pizzas for you. Currently, this is all arrays, but does…
-
Change UIColors to RGB and HSB colors
One dilemma you’ll find when working with colors is switching between color systems. There’s two you’ll most often be using: the Red-Green-Blue or RGB and Hue-Saturation-Brightness or HSB. Download the Exercise file and run. It will give you the HSB value, but what if you want a RGB Value for that color? What if you…
-
Understand ARC
One of those difficult things for even experienced developers to understand is Automatic Reference Counting, or ARC. It is how Swift manages and conserves memory automatically. Take a look at the Exercise file. I have a playground in this project with two classes. One is a pizza topping. One is a Pizza. Look at the…
-
Understand Closures
You’ll find closures throughout the API’s, but you may not know how to use them properly. Let’s take a basic tour of closures. Download the exercise file, and you’ll find a project with a playground. In the playground you’ll find a function to compute a pizza volume. That’s for a round pan pizza, for a…
-
Thrown Errors
There’s many ways to handle errors in Swift. For some errors, using throws is a great way to handle errors without crashing the system. Download the exercise file. You’ll find a project with an embedded playground. While there’s a lot better ways to do this, I’ll use an example of a function coffee(name:) that finds…
-
Swift Strings Are Not C Strings or NSStrings
In many popular programming languages strings are little more than an array of characters, often referred to as C strings since C was one of the first languages to take this approach to strings. As we learned in the last post, with Swift’s use of Unicode characters in extentended grapheme clusters, this gets messed up,…
-
Unicode Characters in Strings
Special characters like emoji, accents, and symbols in your strings are easier to get than you think. This week, we’ll talk about how using Unicode characters in Swift Strings. Open the exercise file and you’ll find a project which we’ll use for this. I just hooked up a label to make a big display of…