Arrays swift


var players:[String] = ["Dhoni", "Kohli", "Rahane", "Sachin"]
print(players[2])
print(players.count)

if players.count >= 11 {
print("complete team")
}else{
print("need more players")
}



//append player(add player)
players.append("Yadav")

//add player at index
players.insert("bhuvi", at: 2)
print(players.count)

players.sort()
print(players)

print(players.contains("Dhoni"))

//remove player
players.remove(at: 1)
players.removeLast()
players.removeFirst()
players.removeAll()
print(players)
Previous
Next Post »