[swift-evolution] Consolidate Code for Each Case in Enum

Charles Srstka cocoadev at charlessoft.com
Mon Jan 9 14:16:09 CST 2017


> On Jan 9, 2017, at 11:54 AM, Tim Shadel via swift-evolution <swift-evolution at swift.org> wrote:
> 
> enum OneOnOneField: Int {
> 
>     var title: String { return "" }
>     var placeholder: String { return "" }
>     var image: UIImage { return UIImage() }
> 
>     case agenda {
>         var title: String { return NSLocalizedString("Agenda", comment: "One on one field header") }
>         var placeholder: String { return NSLocalizedString("Add an agenda", comment: "One on one field placeholder") }
>         var image: UIImage { return #imageLiteral(resourceName: "Agenda-Small") }
>     }
> 
>     case summary {
>         var title: String { return NSLocalizedString("Summary", comment: "One on one field header") }
>         var placeholder: String { return NSLocalizedString("Add a summary", comment: "One on one field placeholder") }
>         var image: UIImage { return #imageLiteral(resourceName: "Summary-Small") }
>     }
> 
>     case date
> 
>     case notes {
>         var title: String { return NSLocalizedString("Personal Notes", comment: "Title for personal notes screen") }
>     }
> 
> }

A thousand +1s from me on this. This would make enums so much more pleasant to work with.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170109/4fa1364c/attachment.html>


More information about the swift-evolution mailing list