[swift-users] Printing Enums?

Jon Shier jon at jonshier.com
Mon Jul 17 17:25:24 CDT 2017


	Certain Objective-C enums don’t print a useful debug description. I usually work around this by implementing CustomStringConvertible (or the debug version) for the type myself. You probably want to file a bug with Apple.


Jon


> On Jul 17, 2017, at 6:15 PM, Michael Rogers via swift-users <swift-users at swift.org> wrote:
> 
> Hi, All:
> 
> Can someone please enlighten me as to why the first enum works as expected, giving me Melbourne, but the second gives UIModalPresentationStyle rather than fullScreen? 
> 
> 
> enum City {
>     case Melbourne, Chelyabinsk, Bursa
> }
> let city = City.Bursa
> 
> print(city)
> // prints "Melbourne"
> 
> let cityName = "\(city)"   // or `let cityName = String(city)`
> // cityName contains "Melbourne"
> 
> // Why doesn't the following work?
> 
> let presStyle = UIModalPresentationStyle.fullScreen
> 
> print(presStyle) // prints UIModalPresentationStyle
> 
> let presStyleName = "\(presStyle)"
> 
> 
> I have an ugly work-around using String UIPresentationStyle tuples, but I'd rather not use it if possible.
> 
> Thanks,
> 
> Michael
> ---------------------------------------------------------------------------
> Dr. Michael P. Rogers
> Associate Professor, Northwest Missouri State University
> Tinkerer-in-Chief and Angel Flight Pilot
> Twitter & Google+:  mprogers at mac.com <mailto:mprogers at mac.com>;  Skype: mprogersatmac.com <http://mprogersatmac.com/>; Facebook: mprogers
> Phone:  309-825-6454 (H);  660-562-1551 (W)
> 
> Thank you, thank you, thank you, and I'd like to thank all the little people -- Tom Thumb, Ant-Man, and, of course, all the Lilliputians -- who made this award possible 😀
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170717/b1e9088d/attachment.html>


More information about the swift-users mailing list