summaryrefslogtreecommitdiffstats
path: root/osdep/macOS_swift_extensions.swift
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2019-03-30 21:26:31 +0100
committerJan Ekström <jeebjp@gmail.com>2019-04-25 23:02:19 +0300
commit71ad1e2f4c2b87e677d01c639dbd3d28c118ac55 (patch)
treebf564e6374790a96f025ea0c44fc57ac7f9f6f5f /osdep/macOS_swift_extensions.swift
parentedbc1999145b5593098f09042947bf1b79323d2e (diff)
downloadmpv-71ad1e2f4c2b87e677d01c639dbd3d28c118ac55.tar.bz2
mpv-71ad1e2f4c2b87e677d01c639dbd3d28c118ac55.tar.xz
cocoa-cb: remove all force unwrappings of optionals
the force unwrapping of optionals caused many unpredictable segfaults instead of gracefully exiting or falling back. besides that, it is bad practice and the code is a lot more stable now.
Diffstat (limited to 'osdep/macOS_swift_extensions.swift')
-rw-r--r--osdep/macOS_swift_extensions.swift16
1 files changed, 8 insertions, 8 deletions
diff --git a/osdep/macOS_swift_extensions.swift b/osdep/macOS_swift_extensions.swift
index cc7438fd8c..7929d48f9a 100644
--- a/osdep/macOS_swift_extensions.swift
+++ b/osdep/macOS_swift_extensions.swift
@@ -21,7 +21,7 @@ extension NSScreen {
public var displayID: CGDirectDisplayID {
get {
- return deviceDescription["NSScreenNumber"] as! CGDirectDisplayID
+ return deviceDescription["NSScreenNumber"] as? CGDirectDisplayID ?? 0
}
}
@@ -37,8 +37,8 @@ extension NSScreen {
repeat {
object = IOIteratorNext(iter)
- let info = IODisplayCreateInfoDictionary(object, IOOptionBits(kIODisplayOnlyPreferredName)).takeRetainedValue() as! [String:AnyObject]
- if (info[kDisplayVendorID] as? UInt32 == CGDisplayVendorNumber(displayID) &&
+ if let info = IODisplayCreateInfoDictionary(object, IOOptionBits(kIODisplayOnlyPreferredName)).takeRetainedValue() as? [String:AnyObject],
+ (info[kDisplayVendorID] as? UInt32 == CGDisplayVendorNumber(displayID) &&
info[kDisplayProductID] as? UInt32 == CGDisplayModelNumber(displayID) &&
info[kDisplaySerialNumber] as? UInt32 ?? 0 == CGDisplaySerialNumber(displayID))
{
@@ -60,11 +60,11 @@ extension NSScreen {
extension NSColor {
convenience init(hex: String) {
- let int = Int(hex.dropFirst(), radix: 16)
- let alpha = CGFloat((int! >> 24) & 0x000000FF)/255
- let red = CGFloat((int! >> 16) & 0x000000FF)/255
- let green = CGFloat((int! >> 8) & 0x000000FF)/255
- let blue = CGFloat((int!) & 0x000000FF)/255
+ let int = Int(hex.dropFirst(), radix: 16) ?? 0
+ let alpha = CGFloat((int >> 24) & 0x000000FF)/255
+ let red = CGFloat((int >> 16) & 0x000000FF)/255
+ let green = CGFloat((int >> 8) & 0x000000FF)/255
+ let blue = CGFloat((int) & 0x000000FF)/255
self.init(calibratedRed: red, green: green, blue: blue, alpha: alpha)
}