[swift-evolution] Ad hoc enums / options

Leonardo Pessoa me at lmpessoa.com
Tue May 31 11:37:03 CDT 2016


This is interesting. I don't think there is anything preventing these
to be internally translated by the compiler as a true enums with
random names (or
any-other-way-we-shall-never-be-able-to-reference-again) thus adding
the needed ObjC interop.

L

On 31 May 2016 at 13:24, Charlie Monroe via swift-evolution
<swift-evolution at swift.org> wrote:
> Most ideas discussed here lately cannot be used from ObjC.
>
>> On May 31, 2016, at 6:20 PM, Kevin Nattinger via swift-evolution <swift-evolution at swift.org> wrote:
>>
>> Definitely an interesting idea, and I like it, but how would this be used from Objective C?
>>> On May 31, 2016, at 9:16 AM, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
>>>
>>> Here's a function signature from some code from today:
>>>
>>> func scaleAndCropImage(
>>>    image: UIImage,
>>>    toSize size: CGSize,
>>>    fitImage: Bool = true
>>>    ) -> UIImage {
>>>
>>>
>>> And here's what I want the function signature to actually look like:
>>>
>>> func scaleAndCropImage(
>>>    image: UIImage,
>>>    toSize size: CGSize,
>>>    operation: (.Fit | .Fill) = .Fit
>>>    ) -> UIImage {
>>>
>>>
>>> where I don't have to establish a separate enumeration to include ad-hoc enumeration-like semantics for the call. A while back, Yong hee Lee introduced anonymous enumerations (and the possibility of anonymous option flags) but the discussion rather died.
>>>
>>> I'm bringing it up again to see whether there is any general interest in pursuing this further as I think the second example is more readable, appropriate, and Swifty than the first, provides better semantics, and is more self documenting.
>>>
>>> Thanks for your feedback,
>>>
>>> -- Erica
>>>
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list