[swift-users] CustomStringConvertible?

Joanna Carter joanna at carterconsulting.org.uk
Sat Sep 9 03:27:23 CDT 2017


Greetings

> Thanks for your reply, Rien. I just tried this again, and now it seems that either is acceptable. Seems a little weird, but I guess I’d rather have more flexibility than less.

> class GPS : Powerable, CustomStringConvertible {
>     // Either of these work
> //    var description: String {
> //        return "I am a GPS"
> //    }
>     var description:String = "I am a GPS"

You can also implement description as a let, since there is no intention to modify it :

class GPS : Powerable, CustomStringConvertible
{
  let description = "I am a GPS"
  
  …
}

Joanna

--
Joanna Carter
Carter Consulting



More information about the swift-users mailing list