Sling Academy
Home/Swift/Page 5

Swift

Everything about the Swift programming language, from basic to advanced, from simple to complex
Working with the insert() method in Swift

Working with the insert() method in Swift

Updated: Apr 17, 2023
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......
Swift: How to append elements to an array

Swift: How to append elements to an array

Updated: Apr 17, 2023
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......
Swift: How to find the length of a given array

Swift: How to find the length of a given array

Updated: Apr 17, 2023
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......

Different Ways to Create an Array in Swift

Updated: Apr 17, 2023
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......

Swift Cheat Sheet (Updated)

Updated: Mar 05, 2023
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......

3 Ways to Generate Random Strings in Swift

Updated: Feb 23, 2023
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......

How to Split a String into an Array in Swift

Updated: Feb 23, 2023
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)......

Swift: 3 ways to count the occurrences of words in a string

Updated: Feb 23, 2023
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......

Swift: Remove Leading and Trailing Whitespace of a String

Updated: Feb 23, 2023
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......

Swift: 4 Ways to Find the Length of a String

Updated: Feb 23, 2023
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”......

Swift: 3 Ways to Check if a String Contains a Substring

Updated: Feb 23, 2023
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......

2 Ways to Reverse a String in Swift

Updated: Feb 23, 2023
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......