I just started with Swift a few days ago and I am struggling with all the different Datatypes...
Lets say we do this:
var myarray = ["justin", "steve", "peter"]
var newString = myarray[2]
so why I cant now print just the "p" from "peter"?
print(newString[0])
---> gives me an error:
"'subscript' is unavailable: cannot subscript String with an Int"
in this topic: [Get nth character of a string in Swift programming language
it says: "Note that you can't ever use an index (or range) created from one string to another string"
But I cant imagine, that there isn't way to handle it...
Because When I do this:
var myarray = ["justin", "steve", "p.e.t.e.r"]
var newString = myarray[2]
let a : [String] = newString.componentsSeparatedByString(".")
print(a[2])
- then it works. It prints (in this case) "t".
So how I can split it "SeparatedByString" 'Nothing'?
Im sure to solve this will help me also at many other problems. I hope I postet the question in the way it should be done.
Thank you for any solution or tips :)