Swift

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

In this tutorial, you will learn how to create a UITabBarController programmatically in Swift. UITabBarController is a container view controller in UIKit that manages a multi-selection interface, where the selection determines which child view controller to display. It’s typically used to organize 2-5 view controllers in a group. Here are some key points about UITabBarController: It…

Read More Create UITabBarController programmatically

In this short Swift code example, you will learn how to disable rotation of the UIViewController if device is rotated right or left. Note, that if your view is embedded into UINavigationController a different approach is needed. Check Swift Code Examples page to learn how to disable rotation of the view if it is embedded…

Read More Disable Rotation of UIViewController

In this short Swift code example, you will learn how to: Initialize an Array with 5 elements in Swift, Remove an element from an array at the specified index. Create an Array Let’s first create a new array with some elements in it. // Initialize Array with 5 elements var myArray = [1,2,3,4,5] // Print…

Read More Remove Element From an Array at Specified Index in Swift

Lets’ create an Array with three elements first. var myArray = [“Swift”, “Objective-C”, “PHP”] Now we can loop through all elements in Array for arrayElement in myArray { print(arrayElement) } Loop through an array of elements and print out element index as well as element value. for (index, element) in myArray.enumerated() { print(“Element index: \(index).…

Read More Loop Through Array Elements in Swift

In this Swift code example, you will learn how to make the music playback slider smoothly move as the music continues to play so that the user is visually aware of how much of the music file has been already played and how much is left to play. Create AVPlayer and AVPlayerItem Create UIButton programmatically…

Read More AVPlayer. Add Periodic TimeObserver to Update Music Playback Slider