Re: [swift-users] CustomStringConvertible?
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 ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] CustomStringConvertible?
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 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 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 >>> 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@swift.org >>> https://lists.swift.org/mailman/listinfo/swift-users >> > ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] CustomStringConvertible?
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 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 >> 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@swift.org >> https://lists.swift.org/mailman/listinfo/swift-users > ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] CustomStringConvertible?
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 > 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@swift.org > https://lists.swift.org/mailman/listinfo/swift-users ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
[swift-users] CustomStringConvertible?
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@swift.org https://lists.swift.org/mailman/listinfo/swift-users