Let's review what you learned in this section, and discuss what's next.
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3535-programming-in-swift/lessons/38
Let's review what you learned in this section, and discuss what's next.
Hi all,
It seems to me like the code for accessing characters in a string in this style seems a little long. I was digging through the Swift documentation and found that you could cast the string as an array and then use normal index syntax like so:
let thirdChar = Array(cafeCombining)[2]
Does this produce the same results and also do you take any optimization hits if you do it this way? Thanks.
As I understand it this method may work but a) is inefficient as it requires a new array to be allocated with the same contents as the string, and b) doesn’t use Apple’s recommended APIs so I’m a bit suspicious of this approach.
For more info find these posts:
Oh interesting. So it appears that the compiler does it much quicker using swift’s recommended API. Those links are were very helpful. Thanks!
This topic was automatically closed after 166 days. New replies are no longer allowed.