Swift 3 Array Tutorials
These are formatted so you can copy the code straight into your Swift Playground files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
//create an empty array containing String types var swift3Array = [String]() swift3Array.append("Tutorials") swift3Array.append("More Tutorials") //remove an item swift3Array.remove(at: 0) //remove first item //remove everything swift3Array.removeAll() //add stuff back... swift3Array = ["CartoonSmart.com" , "Shameless Plug", "Best Tutorials for Swift 3"] // check if the array has a specific thing... for name in swift3Array { //for loop iterates through all Strings in the array if (name == "CartoonSmart.com") { // found the one we are looking for print("found") break } } // check if a specific index equals something if ("Best Tutorials for Swift 3" == swift3Array[2] ) { // remember the 2 in swift3Array[2] means that actually the third item in th array since indexing starts at 0 print("true dat") } |
If you’re looking for places to learn after these Swift Playground examples, check out CartoonSmart.com or SpriteKitLessons.com