Hacker News new | comments | show | ask | jobs | submit login

The author is maybe not aware that there's already a convenience form that doesn't require explicitly making an NSRegularExpression object.

    if name.rangeOfString("ski$", options: .RegularExpressionSearch).location != NSNotFound {
        println("\(name) is probably polish")
    }
That's existing Cocoa API; in Swift (hopefully!) the API can be updated to return nil if there's no match, so that it can read

    if let match = name.rangeOfString("ski$", options: .RegularExpressionSearch) {
        println("\(name) is probably polish")
    }
which I don't think is too bad!



Thanks, included this in the post.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: