Hey there! 馃憢

I’m Luke, an iOS Developer. Welcome to the blog! This is where I will be writing about my experiences using Swift, SwiftUI and any other technology that interests me.

How to Trigger an Action When a SwiftUI Toggle Changes

Sometimes we may need to call an action every time a toggle changes instead of relying purely on a state property to keep our toggle up to date. Luckily this is easy to do. An action can be called when a toggle is updated (or any control that takes in a binding, such as a slider) and a state property will be used to display the state in the control....

August 11, 2022 路 2 min

How to Hide the Tab Bar When Pushing a New View Controller

Sometimes, when using a UITabBarController, you want to push a new view controller without the tab bar. Unfortunately, the default behaviour for a UITabBarController is to show the tab bar no matter how many view controllers have been pushed. Luckily, there is an easy way to elegantly hide the tab bar using the hidesBottomBarWhenPushed property that every view controller has. Example Using Code func moveToNextViewController() { let vc = MyViewController() vc....

July 17, 2022 路 1 min

How to Start a UIKit Project With No Storyboards

In this guide, you鈥檒l learn how to start a new Xcode project without storyboards. I prefer to take a full programmatic approach to laying out my UI so when I start a new project, I always follow these steps to make sure the storyboard has been properly removed. Delete The Storyboard The first and most obvious step is to actually delete the Main.storyboard file. To do so, right-click on the file in the project navigator and select Delete....

June 13, 2022 路 2 min

How to Add a Search Bar to a List in SwiftUI

SwiftUI now has the ability to add a search bar in iOS 15. This is done through the searchable() modifier which adds a search bar under your navigation view automatically. To get started, we need our data and a state property to keep track of the search term. @State private var searchTerm = "" private let cats = ["Persian", "Tabby", "Ragdoll", "Sphynx", "Maine Coon"] Next, we need a computed property to filter our data depending on the search term....

June 8, 2022 路 2 min

How to Install Dependencies With Carthage

Carthage is a dependency manager that makes using third party dependencies in your project easy. It鈥檚 slightly different to its more popular counterpart Cocoapods, where instead of creating an XCWordspace file and modifying files, it instead provides you with binary frameworks which can be imported into your project. This may all sound quite confusing but Carthage is really easy to use and hopefully by the end of this guide you should be up and running in no time....

May 30, 2022 路 4 min

How to Fetch Data From an API in Swift

Introduction Fetching JSON data from a remote API really is the bread and butter of iOS development so it鈥檚 important for you to know how to do it in a neat and reusable way. Today, we will be using Codable and URLSession. Oh, and some generics too. We will be using the website https://jsonplaceholder.typicode.com/todos. This handily provides us with some example JSON data that we can use. [ { "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }, { "userId": 1, "id": 2, "title": "quis ut nam facilis et officia qui", "completed": false } ] Defining Our Model To get started, we first need to define a model for the data....

March 8, 2022 路 4 min