Learn free swift tutorials

Multiple ways to iterate a loop with index and element in array in swift

May 21, 2022 ·  2 min read

This tutorials shows multiple ways to iterate an array with index. Swift provides collection type such as Arrays, sets, and dictionaries. Let’s see an example for multiple ways to iterate an loop with index and an element in Swift array. How to iterate a loop with index an element in Swift Array? We use for loop to iterate an element in swift for-in loop iterates the loop for number of elements in an array....

How to check if a string contains a substring in Swift with example

May 19, 2022 ·  1 min read

This tutorial explains how to check substring exists in a string in swift with examples For example, If a given string is cloudhadoop, substring cloud returns true. How to check if a string contains a substring in Swift? use contains in Swift 4 & 5 versions The string has contain a method that takes substring and returns true if found, else returns false. It does not check case sensitive substrings...

How to Convert String to Int in swift with example

May 17, 2022 ·  2 min read

This article talks about three ways to convert String to Int or String to Int in Swift Language. String and Int are different data types and hold different values. When we want to perform mathematical calculations on strings that contain numbers, we must convert string to int. if a user enters a numeric value in the text box of a web application form, this will be received as input as a string....

How to Split a String by separator into An array ub swift with example

May 16, 2022 ·  1 min read

This article explains about multiple ways to split a string into array in swift 2,3 and 4 with examples How to Split the string by spaces in Swift? There are multiple ways we can do In the Swift 2 version, You can use the componentsSeparatedByString of a string. It returns an array of substrings. import Foundation var name: String = "Hello Welcome to cb " let substrings = name.componentsSeparatedByString(" ") print(substrings[0]); print(substrings[1]); print(substrings[2]); In The Swift 3 version,...

Length of a String in swift with example

May 9, 2022 ·  2 min read

The string contains a group of characters. Characters can be normal alphabets or Unicode characters. The length of a string is a count of the number of characters in a string. For example, If a string is “abc”, Then the length of a string is 3. Length of a String in Swift There are two types of a string. One is a String of normal alphabets without Unicode and emoji characters The second type of a string contains Unicode characters....

You'll get a notification every time a post gets published here.