Author: Sergey Kargopolov

Software developer

Web: www.appsdeveloperblog.com

In this Swift code example, you will learn how to create and display UICollectionView in Swift Programmatically. The Swift code example in this tutorial will cover the following: Create UICollectionView programmatically, Set UICollectionView layout UIEdgeInsets, Set UICollectionView item size(width and height), Set UICollectionView background color, Set UICollectionView Item background-color, Implement UICollectionView Delegate method didSelectItemAtIndexPath to…

Read More Create UICollectionView in Swift Programmatically

In this Swift code example, you will learn how to programmatically create UICollectionView and load a list of images from a remote URL. The below swift code example will cover: Create UICollectionView programmatically Set UICollectionView item size(width and height) Set UICollectionView background color Set UICollectionView Item background-color Implement UICollectionView Delegate method didSelectItemAtIndexPath to handle an…

Read More UICollectionView. Load List of Images From Remote Server Url

In this short Swift code example, you will learn how to determine main screen bounds as well as screen height and width in Swift. Get main screen bounds Get screen width Get screen height // Get main screen bounds let screenSize: CGRect = UIScreen.main.bounds let screenWidth = screenSize.width let screenHeight = screenSize.height print(“Screen width =…

Read More Determine Main Screen Height and Width

In this short Swift code example, you will learn how to determine device orientation in Swift. Determine device orientation when the view is about to appear Determine device orientation when device is being rotated to Landscape or Portrait import UIKit class ViewController: UIViewController { var textView:UITextView? override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_…

Read More Determine Device Orientation in Swift

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 disable rotation of the UIViewController which is embedded into UINavigationController. We will need to override the shouldAutorotate function and return a value of false, Add to current UIViewController a UINavigationController extension. Disable Rotation of UIViewController Complete Code Example in Swift Below is a very simple…

Read More Disable Rotation of UIViewController Embedded Into UINavigationController

In this Swift code example, you will learn how to play the music mp3 file from a remote URL in Swift. The code example below will cover: Create AVPlayer and AVPlayerItem, Create UIButton programmatically, Create AVPlayerLayer and add it as a subview, Handle the Play button action to Pause and Play music, Set UIImage on…

Read More AVPlayer. Play Music MP3 File From a Remote URL In Swift.

In this tutorial, you will learn how to remove the DEBUG banner in the Flutter app. If you run Flutter mobile application on an Android emulator or iOS simulator it will show a DEBUG label in the right side upper corner. Removing the DEBUG Banner The DEBUG label will be automatically removed when you build…

Read More How to Remove the DEBUG Banner in Flutter App

In this Swift code example, you will learn how to add a playback slider to an AVPlayer, so that users can start playing music from any place they wish. The code example below will cover the following: Create AVPlayer and AVPlayerItem, Create UIButton programmatically, Create AVPlayerLayer and add it as a subview, Handle Play Button action…

Read More Add Playback Slider to AVPlayer. Example In Swift.

In this Swift code example, you will learn how to determine user’s current location using CLLocationManager and CLLocationManagerDelegate. The code example below will cover: Request user’s permission for your app to always be able to read user’s location. Optionality you could use requestWhenInUseAuthorization() instead of requestAlwaysAuthorization(), Update projects Info.plist with String values for NSLocationAlwaysUsageDescription and…

Read More Determine User’s Current Location Example in Swift

Error handling is the process of responding to and recovering from error conditions in your mobile app. Some operations aren’t guaranteed to always complete execution or produce a useful output. When an operation fails, it’s often useful to understand what caused the failure, so that your code can respond accordingly. Handle Error with Do, Try…

Read More Error Handling Example in Swift

In this short Swift code example, you will learn how to compare two strings despite their case sensitivity. To do that we will use the caseInsensitiveCompare() function and the ComparisonResult enumeration. Using caseInsensitiveCompare() and ComparisonResult let valueExpected = “SUCCESS” let valueProvided = “success” if valueExpected.caseInsensitiveCompare(valueProvided) == ComparisonResult.orderedSame { print(“Strings are equal”) } In the code example above, the caseInsensitiveCompare…

Read More Case Insensitive Comparison of Strings in Swift

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