Correction/ Clarification. My assumption. The signature I am assuming is
actually:
func scaleAndCropImage(
image: UIImage,
toSize size: CGSize,
fitImage: Bool = false
) -> UIImage {
> On May 31, 2016, at 3:27 PM, Hooman Mehr via swift-evolution
> <[email protected]> wrote:
>
> If we go back to your original example:
>
>
>
> func scaleAndCropImage(
> image: UIImage,
> toSize size: CGSize,
> fitImage: Bool = true
> ) -> UIImage {
>
> There is a different type of sugar that I would like to have: Having label
> stand for `true` when we have a defaulted boolean flag, whose default value
> is false.
>
> At call site we either say:
>
> scaleAndCropImage(image: myImage, toSize: mySize)
>
> or:
>
> scaleAndCropImage(image: myImage, toSize: mySize, fitImage)
>
> We could still use:
>
> scaleAndCropImage(image: myImage, toSize: mySize, fitImage: true)
> or
> scaleAndCropImage(image: myImage, toSize: mySize, fitImage: false)
>
> Note that this is addressing a different situation: When we have multiple
> boolean flag parameters that can be combined like an OptionSet.
>
> This is purely sugar: if the identifier matches the label of a defaulted to
> false boolean flag, it is interpreted as if the flag was passed as true.
> Other than that there is no effect.
>
> I also like your idea as long as we put a limitation like what you proposed:
> Having it strictly be a UInt8 (or whatever) enum. Still the general
> resilience issues with enums remain and may get more complicated with this
> addition.
>
>
>> On May 31, 2016, at 3:00 PM, Erica Sadun via swift-evolution
>> <[email protected] <mailto:[email protected]>> wrote:
>>
>>
>>> On May 31, 2016, at 3:20 PM, Brent Royal-Gordon <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>>> func scaleAndCropImage(
>>>> image: UIImage,
>>>> toSize size: CGSize,
>>>> operation: (.Fit | .Fill) = .Fit
>>>> ) -> UIImage {
>>>
>>> As I said the last time this proposal came up, I think this is great right
>>> up until the moment you need `operation` to be computed or kept in a
>>> variable. Then you need to start copying your anonymous enum type all over
>>> your source, and there's no central place to make changes. The same thing
>>> is true of tuples, but tuples are easy to structure and destructure from
>>> individual values on the spot; anonymous enums aren't really like that.
>>
>> And the obvious answer is you can have up to 255 of these babies for the
>> anonymous enum type, and be able to pass numerical equivalents UInt8 with
>> compile time substitution. That the ad-hoc enumeration is basically a
>> syntactic shorthand for UInt8, with an enforced upper bound compile time
>> check simplifies everything including switch statements.
>>
>> -- E
>>
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected] <mailto:[email protected]>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution