Correction required in A Swift Tour?

It wasn't obvious where this should be posted or how to effect this change, so feel free to reply with any constructive recommendations. I recently downloaded the Playground file A Swift Tour and have been enjoying the tour (the relevant code below is faithfully presented on the live "A Swift Tour" site as might be expected).

Recently, while working through the examples in the Protocols and Extensions the compiler threw an error for the following code taken verbatim from the download:

extension Int: ExampleProtocol {
   var simpleDescription: String {
       return "The number \(self)"
   mutating func adjust() {
      self += 42


The screenshot below indicates that the keyword public should precede the property and the method. Indeed, when the public keyword is added to the code, it compiles beautifully and renders the desired result.
Screenshot 2020-08-26 at 14.44.05

Since the error could be a source of confusion for the intended target audience of A Swift Tour, might it be an idea to have the download and site amended to include the keyword?

Hi @Will-1-Am – thanks for the report. Since ExampleProtocol itself isn't public (it's internal, the default), you shouldn't be getting this error when conforming a type. I can't reproduce this issue with a recent copy of Xcode 12, what version of Xcode are you running?

Thank you for your reply, Ben.

The error manifests in Xcode 11.6. I will give it a try in Xcode 12 also just for fun.

I cannot reproduce the problem with Xcode 11.6. As far as I can see, the public modifier is nowhere used in the Swift code of that Playground file. Did you run the original Playground file, unmodified?

The error was duplicated in Xcode 12 beta 5. Initially, the code ran with the public keywords preceding the property and method. The keywords were then removed and the error reappeared. Eventually, after recompiling, in a step-wise fashion from the top of the page, the error disappeared...

Thank you for your reply, Martin.

A fresh copy of the Playground file runs without issue, so it must be the old file which has been edited. The "old" file was downloaded about a week ago.

Terms of Service

Privacy Policy

Cookie Policy