Skip to content

Instantly share code, notes, and snippets.

@Gabbrolee
Created August 3, 2021 19:46
Show Gist options
  • Save Gabbrolee/bfc25c946e1f9e39838b0a2f9593d829 to your computer and use it in GitHub Desktop.
Save Gabbrolee/bfc25c946e1f9e39838b0a2f9593d829 to your computer and use it in GitHub Desktop.
DAY ONE: ARRAY
//MARKS:- ARRAY
// swift use type inference to know what type of data your array holds and it allows you group of data together into collections and allow you access those values in the array using the index.
var evenNumbers = [ 2, 4, 6, 8]
var songs = [ "Shake it off", "You belong with me", "Back to December" ]
// accessing the position of items in the array, you need to use the array name then the position . the first element is at index 0 and so on
songs[0] // Shake it off
songs[1] // You belong with me
// if you need to confirm the type of data the array holds
type(of: songs) // this is seeing songs as an array of strings
// if you want an array to take any type then you have to declare it as array of Any
var street:[Any] = [ "4, Ohemene Street", "14, kemi Adeosun", "17, Ayoola Street"]
// empty array declaration
var song: [String] = [] // empty array
song[0] = "Shake it Off" // assign the string Shake it Off to index 0f
// the array
var songs1 = [ "Shake it off", "You belong with me", "Back to December" ]
var songs2 = [ "let's go home", "Where have you been", "It's public holiday" ]
var both1 = songs1 + songs2
// or
songs1 += songs2 // append the strings in songs2 to songs1. making songs1 having both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment