var yourArray = [String]()
yourArray.append("String Value")
Or
let someString = "You can also pass a string variable, like this!" yourArray.append(someString)
Added by inserting
Once you have some values, you can insert a new value instead of added. For example, if you want to insert a new object in the beginning of the array (instead of appending it to the end):
yourArray.insert("Hey, I'm first!", atIndex: 0)
let lineCutter = "I'm going to be first soon." let positionToInsertAt = 0 yourArray.insert(lineCutter, atIndex: positionToInsertAt)
var yourOtherArray = ["MonkeysRule", "RemoveMe", "SwiftRules"] yourOtherArray.removeAtIndex(1)
When you know where the values in the array (that is, when you know its index value), the above method is very effective. When the index value starting from 0, the second entry at index 1.
Delete the value without knowing the index case
But if you do not it? If you have an array of hundreds of values, you only know that you want to delete a value "removeme" is equal to it?
if let indexValue = yourOtherArray.indexOf("RemoveMe") { yourOtherArray.removeAtIndex(indexValue) }