O'Reilly logo
  • Gabriel Kieruzel thinks this is interesting:

I say “in effect” because a method that extracts a substring returns, in reality, a Substring instance. The Substring struct is an efficient way of pointing at part of some original String, rather than having to generate a new String. Thus, for example, when we call s.dropFirst() on the string "hello", the resulting Substring points at the "ello" part of "hello", which continues to exist; there is still only one string, and no new string storage memory is required.


Cover of iOS 11 Programming Fundamentals with Swift


Storage memory for string . Struct substring.