swiftxcodeprotocolsswift-playground

Usage of { get set } in protocol causes "Couldn't look up symbols" error


I have been following this tutorial for learning swift programming, and up until the section on Protocols, it has been going flawlessly as per the tutorial. But once I reached the section on Protocols, I began having problems.

Specifically, this minimized code (drastically reduced from the tutorial examples) :

import Cocoa

protocol Vehicle {
    var currentPassengers: Int { get set }
}

struct Car: Vehicle {
    var currentPassengers = 1
}

causes these errors in Xcode:

error: Couldn't look up symbols:
_swift_coroFrameAlloc
_swift_coroFrameAlloc
_swift_coroFrameAlloc
_swift_coroFrameAlloc
_swift_coroFrameAlloc
_swift_coroFrameAlloc
_swift_coroFrameAlloc
_swift_coroFrameAlloc
Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler.

If I comment out that 4th line (the one with { get set }) then all works OK, but of course that makes the variable no longer part of the protocol.

My research shows that I am (meaning, the tutorial is) using { get set } correctly, so what is my issue here?


Solution

  • Your code is correct. You are getting an error because of a known bug in Playground.