Created
October 2, 2022 14:47
-
-
Save AhmedMenaim/e7c3d576a3d97b60fc7cd126ff0d5c96 to your computer and use it in GitHub Desktop.
Menaim Academy - Swift Course - Collection Types - Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// MARK: - What is the array !? | |
// -> [] -> Arranged -> [1,2,3,4] var a = 1, var b = 2 var array = [] | |
// MARK: - Create Array | |
//var stringsArray = [] // -> Will give us an error | |
var stringsArray: [String] = [] // -> Empty Array | |
var numbersArray = [1,2,3,4,5] | |
var newNumbersArray = Array(repeating: 0, count: 5) // Default Value | |
var array = Array(1...5) // Ranges | |
var number5Array = Array(arrayLiteral: 5) | |
// MARK: - Access & Modify Array | |
numbersArray.append(6) // Append | |
// Array -> 0 Index | |
// 0 1 2 3 4 | |
//var numbersArray = [1,2,3,4,5] -> [1,2,7,3,4,5,6] | |
numbersArray.insert(7, at: 2) | |
let firstItem = numbersArray[0] | |
numbersArray += [5] // = Append | |
numbersArray.removeLast() | |
print(numbersArray) | |
numbersArray.removeLast(2) | |
print(numbersArray) | |
numbersArray.remove(at: 2) | |
print(numbersArray) | |
// MARK: - Iterating over arrays => Loops |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment