Swift

In today’s tutorial, you’re going to delve into the world of Swift functions once again, exploring a powerful feature: variadic parameters. This tutorial builds upon the concepts you learned about how to Create a Function in Swift, Nested Functions, and Functions With Default Parameters. If you haven’t checked that out, I highly recommend you give…

Read More Discover Functions with Variadic Parameters in Swift

Adding items to a dictionary is easy, but understanding the options and best practices can make your code cleaner and more efficient. This tutorial will guide you through the various ways to add items to a Swift dictionary, from the simplest syntax to more advanced techniques. 1. Add Item to Dictionary Using Subscript Syntax This…

Read More Add Item to a Dictionary in Swift

In this Swift tutorial, I’ll show you how to add new functionality to existing Swift classes using class extensions. It’s a powerful feature in Swift that lets you add your own methods or computed properties to already-defined classes, making them more versatile. Let’s start with a very simple example. Creating a Simple Extension In Swift,…

Read More Swift Class Extension Explained

The following Swift code example demonstrates how to create a UIWebView programmatically and how to make it render HTML code. To break it into smaller steps, the below code snippet demonstrates how to: Create UIWebView programmatically, Implement UIWebViewDelegate functions webViewDidStartLoad and webViewDidFinishLoad, Make UIWebView render HTML Code. Render HTML in UIWebView import UIKit import WebKit class…

Read More Create UIWebView Programmatically and Render HTML Code

The Swift code example below demonstrates how to customize the UINavigationBar appearance via the AppDelegate.swift file. The blow Swift code example covers: Set UINavigationBar tint color, Set Navigation bar Title color, Set navigation bar ItemButton tint color, Set Navigation bar background image, Set navigation bar Back button tint color. import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate…

Read More Customize UINavigationBar Appearance Programmatically via AppDelegate

In this short Swift code example, I am going to share with you how to load the content of a property file into NSDictionary. And in this particular example, I will load the content of the Info.plist file which is available in our projects. But you can use this approach to load up the content…

Read More Info.plist. Read Content of a Property File in Swift

In this Swift code example, you will learn how to disable UIButton. The quickest way to disable the button in Swift is to simply set the button’s isEnabled property to false. For example button.isEnabled = false.  Below is a complete code example in Swift that demonstrates how to: Create new UIButton, Position button within a view,…

Read More Disable UIButton Example in Swift

In Swift, you can load HTML files into your WKWebView from a file that is part of your App Bundle. Before you use the below code snippet, please make sure that the HTML file you want to display in WKWebView is added to your project. Load Local HTML File to a WKWebView let myUrl = myProjectBundle.url(forResource: “my-html-file”,…

Read More WKWebView. Load HTML File from App Bundle.

In this short Swift code example, you will learn how to check if file exists at specified path. Find a Documents directory on device Check if file exists at specified file path let fileNameToDelete = “myFileName.txt” var filePath = “” // Fine documents directory on device let dirs : [String] = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true) if…

Read More Check if a File Exist

In this tutorial, you will learn how to programmatically create a UITextField in Swift. It will be a short tutorial with a very simple code example, but it will cover all the following: Create UITextField of specific height and width, Position UITextField at the center of the view, Set UITextField backgroundColor, Set UITextField textColor, Set…

Read More Create a UITextField in Swift Programmatically