[swift-users] See documentation comment for discussion

Maury Markowitz maury.markowitz at gmail.com
Sun Jun 19 20:35:36 CDT 2016


> On Jun 17, 2016, at 10:38 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> The standard library includes definitions of these subscripts

But how would one select those in the Xcode UI? The documentation doesn't link off the error (AFAIK) itself, only the code. So one could select, say, the var the error is related to, but not the []'s themselves, no?

>  /// components.  The correct interpretation should be selected
>  /// according to the use case and the APIs involved, so `String`
>  /// cannot be subscripted with an integer.

All true, except, of course, when one is working with strings that really do work perfectly weel qwith 1...2, like the strings I'm processing, which came from 80-column punch cards originally used with LLNL's CDC 6600 (serial #2 IIRC). I had totally forgotten I had written this:

subscript (r: Range<Int>) -> String {
    get {
        let subStart = self.characters.index(self.startIndex, offsetBy: r.lowerBound, limitedBy: self.endIndex)
	let subEnd = self.characters.index(subStart!, offsetBy: r.upperBound - r.lowerBound, limitedBy: self.endIndex)
	return self.substring(with: subStart!..<subEnd!)
    }
}

Anyone have any ideas why this is suddenly throwing an error, not within this extension, but in the code calling it? It's as if it doesn't see the extension.

p.s. Actually that is NOT the code I wrote. The 2.2->3.0b translator mangled the second let, so I'm not 100% sure what it originally said.


More information about the swift-users mailing list