These are formatted so you can copy the code straight into your Swift Playground files.
//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")
}
reference :- http://swift3tutorials.com/
No comments:
Post a Comment