[swift-users] Is there any talk about overloading enum cases with associated values?
Dennis Weissmann
dennis at dennisweissmann.me
Sat Nov 26 14:54:22 CST 2016
I would love to have that! Unfortunately, I didn’t find the time yet to think it through and write a proposal. I often use enums for modeling server calls in small apps and prototypes, something along the lines of
public enum Client {
private static let baseURLComponent = URL(string: "")!
case foo(bar: String)
case foob(bar: String, foobar: String)
private func constructURL() -> URL {
...
}
public func fetch<T: JSONInitializable>(completion: (@escaping(T?, Error?) -> ())) {
URLSession.shared.dataTask(with: constructURL()) { data, response, error in
...
if let data = data {
completion(T.init(json: JSON(data: data)), error)
} else {
completion(nil, error)
}
...
}.resume()
}
}
- Dennis
> On Nov 25, 2016, at 12:37 PM, Adrian Zubarev via swift-users <swift-users at swift.org> wrote:
>
> I’m trying to find any talk on the evolution list about the overloading of enum cases with associated values.
>
> Has this already been discussed?
> Any technical reasons why we don’t have this already?
> Anyone else would want this feature?
> enum MyEnum {
>
> case a. // <—\
> // | should not be allowed!?
> case a(Int) // <—/
>
> // What I want is this:
> case javaScript(String)
> case javaScript(String, scope: Document)
> // instead of `case scopedJavascript(String, scope: Document)`
> }
> Best regards,
>
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161126/bf57d437/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3585 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161126/bf57d437/attachment.p7s>
More information about the swift-users
mailing list