SwiftUI Numbers only TextField with SwiftUI Requiring an input to be numbers only is quite a common task. In this tutorial I will show you how to allow numbers only in a TextField using SwiftUI. Step 1: Change the keyboard type to .decimalPad The first step in this task is to change the keyboard type to
How to How to add a delay to code in Swift In this tutorial you will learn how to add a delay to your code. To add a delay to your code we need to use GCD. GCD has a built in method called asyncAfter, which will allow us to run code after a given amount of time. The code is
Swift How to convert Dictionary to Json with Swift It is a common task to convert a Dictionary to JSON. In this tutorial I will show you how you can do just that, luckily for us, Swift makes this incredibly easy. A quick note before we get started, the dictionary's value needs conform to Encodable or Codable.
Swift How to replace characters in string with Swift In this tutorial you will learn how to replace characters in a String using Swift. We will be using the following methods replacingOccurrences, replacingCharacters as well as replaceSubrange. Replace characters with replacingOccurrences method The first method we are going to look at is replacingOccurrences. Two things to note about this
SwiftUI How to make SwiftUI view fill width or height of screen In this tutorial I will show you how to make a view fill the width or height of the parent view or fill the screen. It is often required that a view fill a space, whether it is width, height or both. Luckily for us SwiftUI makes this very easy
How to How to get index and value from for loop with Swift Sometimes I find that I need to get both the index and the value when I am looping through an array. In this tutorial I will show you how to get both. I have the following array of programming languages: let languages = ["Swift", "Kotlin", "JavaScript&
Swift How to save a file from a URL with Swift In this tutorial I will show you how you can download a file from a given URL and then save it locally using Swift. Setting up the local file URL The first thing that I want to do is to setup the local file url. In this tutorial I will
UserDefaults How to store a date in UserDefaults with Swift UserDefaults can be a useful tool to store small amounts of information. In this tutorial I will show you how you can store a Date in UserDefaults using Swift. Storing a date in UserDefaults Below is the code that we will use to save the date: let defaults = UserDefaults.standard
Swift How to save an image to file with Swift There are numerous reasons to save an image to a file using Swift. In this tutorial I will show how you can do that with just a few lines of code. Before we get started I want to add a method that we will use in both saving of a
Swift How to save data to file with Swift There are many reasons that we might need to save data to a file as an app developer. We might need to save an image, or text or something else. In this tutorial I will show you how we can save a string to a file, but this can be
Swift How to save/write Json to file with Swift In this tutorial I will show you two methods that you can use to write JSON data/string to a file using Swift. Save JSON string to file Saving a JSON string will be the same as saving any other kind of string. Since Swift will see it as a
CocoaPods How to Remove CocoaPods from your Project In this tutorial I will show you how to you can remove Cocoapods from your project. Removing Cocodpods is extremely easy to do all we need to do is to install two Ruby gems: sudo gem install cocoapods-deintegrate cocoapods-clean Now that we have the required gems, we can deintegrate and
Swift How to sort a dictionary by value with Swift Every now and then you might need to sort a dictionary by value, luckily, dictionary comes with a sorted method built in. I am going to use the following dictionary as an example: let dictionary = [ "a": "A", "b": "B", "c"
JSONEncoder How to Convert an object to JSON with Swift There could be a few reasons why you would want to convert a swift object to JSON. In this tutorial we will take a look at how we can convert a swift object to a JSON string and how to convert the JSON string to a swift object. First, let&
Swift Hide home indicator with Swift The iPhone X removed the home button and replaced it with what Apple calls the home indicator. Apple has allowed us to hide the home indicator which can be useful if your app needs to hide the indicator. Some examples could be for a video player app, photo app, map/
Swift Hide navigation bar on Scroll or Tap with Swift Have you noticed on some apps where the navigation bar will hide when you start scrolling or if you tap? In this tutorial we will look at how we can do this. The best part about this functionality is how easy it is to implement. Links * Hide on scroll * Hide
UITableView Create a UITableView with Swift In quite a few of my tutorials I need to add a section that will explain setting up a UITableView even if the tutorial does not focus on UITableView specifically. I do this so that readers can see exactly what I have done from the start, who knows, maybe their
UITableView Change UITableView separator color In this quick tutorial I will show you how to change a UITableView's separator color. There are two ways to do this, both are very easy, but there is one that I personally prefer to use. Links * Change separator color with Interface Builder * Change separator color with Swift(
SwiftUI Pass SwiftUI view as argument to another view I assume since you are reading this article that you want to be able to pass a view or multiple views as an argument to another view using SwiftUI. In this tutorial we will learn how we can use ViewBuilder to achieve this. Step 1: Create a custom view This
SwiftUI SwiftUI TextField Character Limit I have written about how to add a character limit to UITextField so I thought that I might as well write a tutorial on how to add a character limit to a SwiftUI TextField. There are few things that change when doing it for SwiftUI. These changes are mainly due
SwiftUI Resize an image with SwiftUI Images are not always the exact size that we need which is what leads me to writing this tutorial. Depending on the situation you might have an image that is too big or too small. > TLDR: To resize an image we need to use the resizable view modifier on
Swift How to convert array to string with Swift In some situations one might want to convert an array of strings to a string. There are a few ways to do this, all are quick and easy but for most use cases the simplest solution will be the best solution. Array.joined Array.joined is the simplest solution out
Swift Get keyboard height in SwiftUI I have written about getting the height of the keyboard before, you can find that article here [https://programmingwithswift.com/keyboard-height-with-swift/]. In this article I am going to be changing it up bit, we will be looking at how to use @Published, ObservableObject and @ObservedObject which can make it a
UITableViewCell UITableViewCell swipe actions with Swift iOS 11 brought a new way to add custom swipe swipe actions to UITableViewCell's. In this tutorial we will learn how to add those swipe actions to table view cells, as well as go through some of the things to look out for when adding swipe actions. When
Swift Remove UITableViewCell highlight/selection color with Swift This is one of those annoying default behaviours that iOS has. Below is a one liner that will help you remove the cell highlighting. To remove the table view cell highlight/selection color all you need to do is this: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell