BSM

May 22 2020

Featuring:

HWS+

HWS+ is an all new service from Hacking With Swift. As of writing, it has 3 courses, which each have a few sections. Until WWDC, HackingWithSwift will publish a new section to one of the 3 courses every day, which afterwards will be every few days.
I can say, after watching all the videos that are released, that they are from really high quality(not only the resolution, also the content🙂!), and are really recommended if you want to level up in your swift and iOS development skills.
Once you are there, be sure to check out the other courses they have here


How to insert an element to the start of an array.

Overview

If you have an array, you can add elements to it using the .append method on the array. This method will add the element to the end of the array. But, you don’t always want to do that. Sometimes you would want to add the element to the beginning of an array. There comes the insert(at:) method in place.

Usage

With the insert(at:) method, you can append an element to an array at any location of the array. For example, to the beginning of the array. Like this:

var array = ["is", "an", "array"]
array.insert("This", at:0) // The array is now: ["This",is","an", "array"]

This code will append the word “array” to the variable array at index 0, which is the beginning.

Of course, you can also pass it in at the second index, which is, using the example above, appending the element to the end.

If you pass in a Int to the at: argument that is larger than the number of elements in the array plus 1(In programming, you count from 0 upwards, so the first element is 0, second 1 etc.). If you do, then the app will crash as it cant append an element to index 5, if it only has 3 elements.