Swift is still sometimes so cumbersome

On this particular question: to avoid a memory leak you are possibly going to hit in this very use case. Imagine the string was 100mb, and you only want the first 100 characters stored in body. If body is a long-lived variable you are essentially leaking 100mb for the lifetime of body. There was recently a long thread investigating a major memory leak in a server-side NIO app that ended up being a variant of this problem (only with Data and ByteBuffer). This leak scenario was such a problem for Java that they changed string's substring op to make a copy (it used to share storage). But this messed other people up because that means substring ops go from being O(1) to being O(n).

15 Likes