Reputation: 4519
I have a array:
[h,e,l,l,o]
And i want to replace an value on the index, for example i want to change the first l at index 2. I know the index so that is not a problem, the only problem is to replace that value.
How can i do this?
Upvotes: 3
Views: 17157
Reputation: 1251
As mentionned here https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html
You can modify your array like that:
var array = ["h", "e", "l", "l", "o"]
array[2] = "Six eggs"
Upvotes: 1
Reputation: 1752
the insert
function will add a new value to the array, what you need to do is simply
var newCharacter = "a"
arr[2] = newCharacter
Upvotes: 14