Okay, straight to the point 🙃

import Cocoa

// StringLiteralConvertible with Regular Expressions
// Example of using Swift literal convertible to provide convenient shorthand initializers for custom objects

// Create a Swift wrapper around NSRegularExpression
struct Regex {
    let pattern: String
    let options: NSRegularExpression.Options
    
    private var matcher: NSRegularExpression {
        do {
            let response = try NSRegularExpression(pattern: self.pattern, options: self.options)
            return response
        } catch {
            fatalError()
        }
    }
    
    init(pattern: String, options: NSRegularExpression.Options = []) {
        self.pattern = pattern
        self.options = options
    }
    
    func match(string: String, options: NSRegularExpression.MatchingOptions = []) -> Bool {
        return self.matcher.numberOfMatches(in: string, options: options, range: NSMakeRange(0, string.utf16.count)) != 0
    }
}

// Extend Regex to support regular expression literal
extension Regex: ExpressibleByStringLiteral {
    init(unicodeScalarLiteral value: String) {
        self.pattern = "(value)"
        self.options = []
    }
    
    init(extendedGraphemeClusterLiteral value: String) {
        self.pattern = value
        self.options = []
    }
    
    init(stringLiteral value: String) {
        self.pattern = value
        self.options = []
    }
}

// Now we can do this
let string: String = "foo bar baz"
let regex: Regex = "bar"
print(regex.match(string: "bar"))