diff --git a/osdep/mac/swift_extensions.swift b/osdep/mac/swift_extensions.swift index 2399c86509..e49806aaa0 100644 --- a/osdep/mac/swift_extensions.swift +++ b/osdep/mac/swift_extensions.swift @@ -32,8 +32,9 @@ extension NSScreen { } public var name: String { - // force unwrapping is fine here, regex is guaranteed to be valid - let regex = try! NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive) + guard let regex = try? NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive) else { + return localizedName + } return regex.stringByReplacingMatches( in: localizedName, range: NSRange(location: 0, length: localizedName.count), diff --git a/video/out/mac/view.swift b/video/out/mac/view.swift index 91ace66245..4921b7512c 100644 --- a/video/out/mac/view.swift +++ b/video/out/mac/view.swift @@ -64,9 +64,10 @@ class View: NSView, CALayerDelegate { } func isURL(_ str: String) -> Bool { - // force unwrapping is fine here, regex is guaranteed to be valid - let regex = try! NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$", - options: .caseInsensitive) + guard let regex = try? NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$", + options: .caseInsensitive) else { + return false + } let isURL = regex.numberOfMatches(in: str, options: [], range: NSRange(location: 0, length: str.count))