When looking at its readme file, it seems like it’s only a command-line tool. However, SourceKitten also includes a framework called
SourceKittenFramework that we can use to build programs to analyse and inspect Swift code ourselves. It’s only usable in a Mac app and does not support iOS, tvOS, or watchOS.
In this article, we will first start by integrating the framework into our project. Next, we will see…
In this short article, we will explore how to add a view to our apps, where users can draw with their finger.
Creating a drawing is quite easy. First, we will see how to get the positions of touches and track movements. The next step is to connect these points in a
CGContext to get our drawing. Finally, we will see how to reset and export the created drawing as a
We start by tracking the touches inside of the view.
// 1 — First, we create a reusable
UIView subclass to wrap the drawing function. In this…
Whenever we are dealing with measurements in our apps and need to convert one unit to another (e.g. an imperial unit like inches to a metric unit like meters), we can write the conversion ourselves. However, this can get quite complicated and error-prone.
Instead, Apple provides a convenient way of dealing with units, measurements, and their conversion by providing a struct called
Measurement. A measurement holds a value and a unit, and it can be converted to other units of the same dimension.
In this article, we will explore Swift’s
Measurement. To do this, we will first see…
Many big apps — like YouTube, Twitter, and Amazon — allow their users to switch between a secured text field and a normal text field whenever a password needs to be entered. This is a good user experience because it’ll be very frustrating for your users to need multiple tries to log in just because they have a complex password and made a spelling mistake.
In this piece, we’ll explore how to recreate this function in SwiftUI. First, we’ll see how to use a
SecureField to obscure the entered text. …
Many macOS apps — like Safari, Finder, Mail, and Xcode — use split views to divide their content into separate areas. This allows a user to decide how to size different parts of the app themselves.
Coming from an iOS background, I was surprised how many fewer references, articles, and documentation exist for macOS development; thus, I decided to write down my experiments on how to use an
In this tutorial, we’ll first add a split view via a storyboard and see how to add more panels. Next, we’ll explore how to recreate Xcode’s segmented control to show and…
When working with collections like arrays or sets, we can use so-called higher-order functions like
map to transform each element of the collection or
filter to get a subset of the collection’s elements.
A higher-order function is a function that takes or returns other functions. If you are new to them, the site Use Your Loaf gives a great overview.
In this article, we will look at a new way of using them with Swift’s KeyPaths.
First, we will explore KeyPaths to see what they are and how they can be used. Later, we will look at new implementations of…
Even in simple apps we are often dealing with multidimensional data. These are elements which contain more than one value, e.g. a struct
User with the properties
address. Performing queries on these elements based on multiple parameter can be quite time consuming, especially when searching through 100 000 or even 1 000 000 elements.
In this article we will explore socalled k-d trees to increase the performance of our apps. First, we will see what a k-d tree is and how it structures and stores data. Next, we will look at the framework KDTree, which allows…
In this article, we will explore how to create radar charts in Swift to plot our data.
A radar chart is a special kind of chart with a web-like structure and star-shaped forms, thus, sometimes it’s also called spiderweb chart or star plot. A good example can be seen in the image above.
We won’t create such charts from scratch, instead we will use the framework Charts, which contains eight different types of charts, including these radar charts.
To see how to use this framework, we will try to recreate the chart from above, which is included in the project’s…
Once the amount of sections and rows in an
UITableView becomes too large, your users will have a hard time finding and scrolling to a particular entry. This problem can be solved by adding a section index to your tableview, so that the user can jump straight to a section with only one single tap. Apple uses such indices whenever they need to show long lists, e.g. in Music, Contacts or iTunes U.
In this article we will see how easy it is to add such an index.
Before we add a section index, we first need to have an…
In this article, we will explore three property wrappers to enforce policies for our properties. By using them, we can make sure these properties are only used as they should be.
The first property wrapper will assure that encapsulated values can expire and are inaccessible after a given time has elapsed. In a second example, we will create one that ensures a value can only be updated once.
Each following update of this value will fail. The final property wrapper makes sure that the wrapped value is only changed within predefined steps.
For each of these wrappers, we will look…
Working as an iOS and Android dev. Also going to finish my master degree in computer science anytime soon now!