3 ms·
The author is maybe not aware that there's already a convenience form that doesn't require explicitly making an NSRegularExpression object. if name.rangeOf
by kenferry 12y ago
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!
- subdigital 12y agoThanks, included this in the post.