Overview In Swift, the insert() method has 2 variants: insert(_:at:) and insert(contentOf:at:). insert(_:at:) insert(_:at:) is used to insert a single element at the specified position in a given array. The syntax......
Using the append(_:) method Appending elements to an array means adding new elements at the end of the array. You can do that in Swift by using the append(_:) method. Note that this method changes the original array and does not......
This short and straightforward article shows you a couple of different ways to find the length of a given array in Swift. The easiest approach is to use the count property on the array. This property returns the number of elements......
An array in Swift is a collection of values of the same type that are stored in an ordered list (with that being said, it’s possible to construct an array with mixed types, and you will learn how to do so in the final section of......
This comprehensive Swift cheat sheet covers the key concepts and most commonly used language features, syntax, and best practices (note that programming experience is required to get the most out of the cheat sheet). Basic......
This practical, succinct article walks you through 3 different ways to generate a random string in Swift. Without any delay, let’s get started. Using UUID UUID stands for “Universally Unique Identifier” and is a......
In Swift, you can split a string into an array by using the split() method. The split() method Syntax: func split(separator: Character, maxSplits: Int = default, omittingEmptySubsequences: Bool = default)......
This concise, example-based article walks you through 3 different approaches to counting the occurrences of words in a given string in Swift. Without wasting any more time, let’s dive in. Using Dictionary and For Loop One way......
This practical article walks you through a couple of different examples that demonstrate how to remove leading and trailing whitespace, separately or together, from a string in Swift. Trim both leading and trailing whitespace You......
This concise, example-focused article walks you through 4 different approaches to getting the length of a given string in Swift. Without any further ado, let’s get our hands dirty with code. Using the “count”......
This succinct, practical article walks you through 3 different approaches to checking if a string contains a substring or not. Without any further ado, let’s get started. Using the contains() method The contains() method is a......
When developing applications with Swift, there might be cases where you need to reverse a given string. For example, reversing a string can help you check if it’s a palindrome (a string that reads the same forwards and backward) or......