[swift-users] CustomStringConvertible?

Rien Rien at Balancingrock.nl
Sat Sep 9 01:43:07 CDT 2017


Ah, yes. It is possible to ‘store’ it as a fixed string.
But I would still expect the compiler to treat it as if it were a computed property.
Given that this is a protocol and a protocol cannot define stored properties.
(yet anyway)

OTOH, what do I know about compilers… lol!

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl - An HTTP(S) web server framework in Swift







> On 08 Sep 2017, at 20:26, Michael Rogers <mprogers at mac.com> wrote:
> 
> 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.
> 
> protocol Powerable {
>     var isOn:Bool { get set } // Must have get and set
>     var usesDC:Bool { get } // Must have get, may have set
>     func turnOn()
>     func turnOff()
> }
> 
> class GPS : Powerable, CustomStringConvertible {
>     // Either of these work
> //    var description: String {
> //        return "I am a GPS"
> //    }
>     var description:String = "I am a GPS"
>     var isOn: Bool = false
>     var usesDC: Bool = false
>     
>     // does the obvious
>     func turnOn(){
>         isOn = true
>     }
>     
>     // does the obvious
>     func turnOff() {
>         isOn = false
>     }
> }
> 
> print(GPS()) // output: I am a GPS (both cases)
> 
> Michael
> 
>> On Sep 8, 2017, at 1:21 PM, Rien <Rien at Balancingrock.nl> wrote:
>> 
>> It cannot be ‘stored’ I would think.
>> I always compute my implementations.
>> 
>> Regards,
>> Rien
>> 
>> Site: http://balancingrock.nl
>> Blog: http://swiftrien.blogspot.com
>> Github: http://github.com/Balancingrock
>> Project: http://swiftfire.nl - An HTTP(S) web server framework in Swift
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> On 08 Sep 2017, at 19:47, Michael Rogers via swift-users <swift-users at swift.org> wrote:
>>> 
>>> Quick question (for my own edification, as well as to demonstrate to my students the power of this mail list 😉), is CustomStringConvertible a stored property or a computed property? The docs say the latter, but when using Xcode’s fabulous FIX button, it seems to imply it’s a stored property. 
>>> 
>>> Michael
>>> _______________________________________________
>>> swift-users mailing list
>>> swift-users at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>> 
> 



More information about the swift-users mailing list