New valuetype for enums to convert a minimum and maximum value into Range<Int>
✓ Published0🌍 Public
MMoximillian
Last edited Mar 24, 2016
Created on Mar 24, 2016
This example demonstrates a custom Swift enum value type that converts string literals into `Range<Int>` values, enabling pattern matching and range checks for age categories. The `StringRangeRawValue` struct conforms to `StringLiteralConvertible` and `Equatable`, parsing comma-separated strings like "0,1" into ranges. An `AgeGroup` enum uses this type for cases such as `.Infant`, `.Toddler`, and `.Child`. The code shows two use cases: a `switch` statement matching an integer age against enum values, and an `if` statement using the `~=` operator to test whether a value falls within a range.
AI-generated description