Re: [swift-users] Printing Enums?

2017-07-17 Thread Slava Pestov via swift-users
There’s already a radar filed for this (I don’t know if there’s a JIRA bug 
though).

The problem is that the standard library’s reflection mechanism only knows how 
to map the in-memory representation of an enum to a case name for native Swift 
enums. Objective-C enums are represented by their ‘raw value’, and we don’t 
store the mapping in a way that’s accessible to the reflection code.

Slava

> On Jul 17, 2017, at 3:33 PM, Alex Blewitt via swift-users 
>  wrote:
> 
>> On 17 Jul 2017, at 15:15, Michael Rogers via swift-users 
>> > 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?
> 
> Sure - it's because it's an alias that is imported via Objective-C rather 
> than defined in Swift:
> 
> typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
> UIModalPresentationFullScreen = 0,
> UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2) 
> __TVOS_PROHIBITED,
> UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2) 
> __TVOS_PROHIBITED,
> UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),
> UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),
> 
> (you can see this in the UIViewController.h file in the UIKit, which is found 
> underneath your Xcode install)
> 
> The importer notes that the name of such typedef'd constants effectively 
> become translated into an enum as far as Swift source code is concerned, but 
> it's a different kind of case.
> 
> Having said that, it might be a bug in the case that the description of the 
> constant isn't the name of the element type. It would be worth raising this 
> on bugs.swift.org  and use this example in case 
> there's something that can be done to fix it.
> 
> Alex
> 
> ___
> 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] Printing Enums?

2017-07-17 Thread Alex Blewitt via swift-users
> On 17 Jul 2017, at 15:15, Michael Rogers via swift-users 
>  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?

Sure - it's because it's an alias that is imported via Objective-C rather than 
defined in Swift:

typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2) 
__TVOS_PROHIBITED,
UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2) 
__TVOS_PROHIBITED,
UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),
UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),

(you can see this in the UIViewController.h file in the UIKit, which is found 
underneath your Xcode install)

The importer notes that the name of such typedef'd constants effectively become 
translated into an enum as far as Swift source code is concerned, but it's a 
different kind of case.

Having said that, it might be a bug in the case that the description of the 
constant isn't the name of the element type. It would be worth raising this on 
bugs.swift.org and use this example in case there's something that can be done 
to fix it.

Alex

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Printing Enums?

2017-07-17 Thread Jon Shier via swift-users
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 
>  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+:  mprog...@mac.com ;  Skype: 
> 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@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] Printing Enums?

2017-07-17 Thread Michael Rogers via swift-users
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+:  mprog...@mac.com;  Skype: 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@swift.org
https://lists.swift.org/mailman/listinfo/swift-users