Swift

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

There are a few different ways of how to create an Array with default values in Swift. Below are a few Swift code examples of creating an Array. Each example creates an array with some initial values. Create an Array of Strings var appleProgrammingLanguages: [String] = [“Swift”, “Objective-C”] Thanks to Swift’s type inference, you don’t…

Read More Create an Array with Default Values in Swift

In this tutorial, you will learn how to determine the current device model in Swift. To determine the current device model in Swift, you can use the utsname struct provided by the Darwin framework, which contains information about the system. This method involves getting the machine hardware description and then mapping it to the corresponding device…

Read More Determine Current Device Model in Swift

To present a ViewController in a NavigationController you can wrap ViewController into a NavigationController as it is in the example below. Then present NavigationController which contains ViewController. // Register Nib let newViewController = CustomSignupViewController(nibName: “CustomSignupViewController”, bundle: nil) let navigationController = UINavigationController(rootViewController: newViewController) // Present View “Modally” self.present(navigationController, animated: true, completion: nil)  

Read More Present ViewController in NavigationController