What should be called the idiomatic Swift code equivalent to pythonic?

Python has a phrase used to describe code written using Python idioms (for-in loops vs for loops, etc.). We say that such a code is Pythonic.

Is there a similar term for the new Swift language for Apple? Swiftonic? Swiftic?

Are we just stuck with idiomatic fast code (description, not term)?

Just to give you an idea of ​​what I'm talking about, here is an example. Both blocks of code find the index of the letter in the string:

Non-swiftic (?) Code [bad] :

// extension method on the String class
func findIndexOf(char : String) -> Int? {

    for var i = 0; i < countElements(self); ++i {
        var ch = String(Array(self)[i])
        if String(ch) == char {
            return i
        }
    }

    return nil
}

Swiftic (?) Code [good] :

// extension method on the String class
func findIndexOf(char : String) -> Int? {

    for (index, ch) in enumerate(self) {
        if String(ch) == char {
            return index
        }
    }

    return nil
}
+4
source share

All Articles