Category: 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…
-
Strings in Swift: Going back to BASICs
A few tips ago, we went under the hood with unicode Characters and their relationship to the Swift String type. For most, that’s great theory, but how does it apply to strings, not characters? When I started programming back in the 1980’s, I had three string functions in BASIC: RIGHT$, LEFT$, and MID$. Let’s create…
-
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…
-
Actions in Table Views
Sometimes table views could use a few buttons. There’s two delegates which create swipe buttons on table view cells. Let’s learn how you can implement these buttons and an interesting hidden feature you can do with them. There is two delegate methods, one for the leading swipe configuration and one for the trailing Swipe configuration.…
-
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…