Playing with Swift

Let say that we have an array of strings:

var cities: [String] = [“San Francisco”, “Denver”];

You can change one string elements of this array given an index.
In this case we change from “San Francisco” to Miami:

cities[0] = “Miami”;

 

Now, let assume we wish to print the last letter of the first string in the array.

This first intent fails:

println(cities[0][advance(cities[0].startIndex, 4)]);

This will fail too:

let index = 4;
println(cities[0][index]);

 

However, this will success:
println(cities[0][advance(cities[0].startIndex, 4)]);

© 2014, Alejandro G. Carlstein Ramos Mejia. All rights reserved.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

*