<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">I agree. These are different proposals that can coexist but I think they should be evaluated separately by the community.<br><br></div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:swift-evolution@swift.org">Vladimir.S via swift-evolution</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">27/05/2016 08:05 AM</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:cocoadev@charlessoft.com">Charles Srstka</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:swift-evolution@swift.org">swift-evolution</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [swift-evolution] [Proposal] Enums with static stored propertiesfor each case</span><br><br></div>Correct me if I'm wrong, but this idea with accessors is not the same as <br>static properties for each case. The one of ideas of initial proposal - <br>static(!) values would be created only once and it is important in case it <br>is expensive to create such value(or if should be created only once per case)<br><br>The suggested solution based on 'accessor' - will create assotiated <br>properties each time the enum instace created, for each instance of enum type.<br><br>We can have something like the example with accessors now :<br><br>enum MyError: ErrorProtocol {<br> struct MyErrorInfo {<br> let localizedFailureReason: String<br> let url: String<br> }<br><br> case fileNotFound(url: String)<br> case fileIsCorrupt(url: String)<br><br> var info : MyErrorInfo {<br> switch self {<br> case fileNotFound(let url) : return <br>MyErrorInfo(localizedFailureReason: "File \"\(url.lowercased())\" not <br>found.", url: url)<br><br> case fileIsCorrupt(let url) : return <br>MyErrorInfo(localizedFailureReason: "File \"\(url.lowercased())\" is <br>corrupt.", url: url)<br> }<br> }<br>}<br><br>var e = MyError.fileNotFound(url: "http://something.some")<br>var info = e.info<br>print(info.localizedFailureReason, info.url)<br><br>But yes, such MyErrorInfo will be created on each `info.` call. This is <br>worse that create MyErrorInfo once per each enum instance initialization, <br>but IMO these solutions are close enough.<br><br>In any case, I don't see why tuple for enum and enum with `accessor` can <br>not co-exists.<br><br>On 27.05.2016 2:28, Charles Srstka via swift-evolution wrote:<br>>> On May 26, 2016, at 4:47 PM, Brent Royal-Gordon via swift-evolution<br>>> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:<br>>><br>>> - Abusing rawValue is just that: an abuse.<br>><br>> In addition, enums with associated types can’t have rawValues.<br>><br>> Why is this relevant, you may ask? Because error enums are a huge use case<br>> for something like this. Being able to do the below would be great:<br>><br>> enum MyError: ErrorProtocol {<br>> accessor var localizedFailureReason: String<br>> accessor var url: NSURL<br>><br>> case FileNotFound(url: NSURL) {<br>> self.localizedFailureReason = “File \"\(url.lastPathComponent ??<br>> “”)\” not found.”<br>> self.url = url<br>> }<br>><br>> case FileIsCorrupt(url: NSURL) {<br>> self.localizedFailureReason = “File \"\(url.lastPathComponent ??<br>> “”)\” is corrupt.”<br>> self.url = url<br>> }<br>> }<br>><br>> This would be much cleaner than the existing method of using a switch to<br>> create a userInfo dictionary for creating an NSError to send to<br>> -[NSApplication presentError:] and similar methods.<br>><br>> Charles<br>><br>><br>><br>> _______________________________________________<br>> swift-evolution mailing list<br>> swift-evolution@swift.org<br>> https://lists.swift.org/mailman/listinfo/swift-evolution<br>><br>_______________________________________________<br>swift-evolution mailing list<br>swift-evolution@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-evolution<br></body></html>