Calculating risk levels Let's consider following function that return some risk levels enum type:

func calculateRiskLevel()-&gt; ResultFirstLevels
{
    let result = self.result
    if result &lt; 1
        {
            return .Level1
        }
    else if result &gt;= 1 &amp;&amp; result &lt; 5
        {
            return .Level2
        }
    else if result &gt;= 5 &amp;&amp; result &lt; 10 
        {

            return .Level3
        }
    else
        {
            return .Level4
        }

}


I'm pretty sure there is a more clever way to achieve that.

I was thinking about a dictionary with some key-value coding, but how can I incorporate conditional statements within keys?

Could you suggest some "more professional" way to deal with such parsing with conditional statements?
If you need risk level to be an enum (which sounds like good idea anyway), it would be nice to tightly couple the meaning of, say, Risk.Level2 with the range of raw values it represents, such as 1..&lt;5. In other words, the enum itself should define all the applicable ranges. Depending on your specific needs, one of the following two approaches may be along the lines of what you're looking for:

enum Risk {

    case Level1, Level2, Level3, Level4

    var range: Range&lt;Int&gt; {
        switch self {
        case Level1: return 0..&lt;1
        case Level2: return 1..&lt;5
        case Level3: return 5..&lt;10
        case Level4: return 10..&lt;Int.max
        }
    }

    init(_ risk: Int) {
        switch risk {
        case Level2.range: self = Level2
        case Level3.range: self = Level3
        case Level4.range: self = Level4
        default: self = Level1
        }
    }
}

Risk(5) //--&gt; Risk.Level3


Or:

enum Risk: Int {

    case Level1 = 0
    case Level2 = 1
    case Level3 = 5
    case Level4 = 10

    var range: Range&lt;Int&gt; {
        switch self {
        case Level1: return Level1.rawValue..&lt;Level2.rawValue
        case Level2: return Level2.rawValue..&lt;Level3.rawValue
        case Level3: return Level3.rawValue..&lt;Level4.rawValue
        case Level4: return Level4.rawValue..&lt;Int.max
        }
    }

    init(_ risk: Int) {
        switch risk {
        case Level2.range: self = Level2
        case Level3.range: self = Level3
        case Level4.range: self = Level4
        default: self = Level1
        }
    }
}

Risk(5) //--&gt; Risk.Level3


This would all be much nicer if we could have enum Risk: Range&lt;Int&gt;. Unfortunately, Range&lt;Int&gt; cannot be expressed as a literal, so cases could not be assigned rawValues...