 
     /// The key name corresponding to the attribute.
     public var keyName: NSAttributedString.Key {
-        var name: NSAttributedString.Key!
-
-        // Bug in Swift prevents us from putting directives inside switch statements (https://bugs.swift.org/browse/SR-2)
-
-        #if os(watchOS)
-        #else
-            switch self {
+        let name: NSAttributedString.Key
+
+        switch self {
+        #if !os(watchOS)
             case .attachment: name = .attachment
             case .shadow: name = .shadow
-            default: break
-            }
-        #endif
-
-        #if os(macOS)
-            switch self {
+        #endif
+        #if os(macOS)
             case .cursor: name = .cursor
             case .markedClauseSegment: name = .markedClauseSegment
             case .spellingState: name = .spellingState
             case .superscript: name = .superscript
             case .textAlternatives: name = .textAlternatives
             case .toolTip: name = .toolTip
-            default: break
-            }
-        #endif
-
-        switch self {
+        #endif
         case .baselineOffset: name = .baselineOffset
         case .backgroundColor: name = .backgroundColor
         case .expansion: name = .expansion

            return (val as! NSNumber).doubleValue
        }

        var ret: Attribute!

        // Bug in Swift prevents us from putting directives inside switch statements (https://bugs.swift.org/browse/SR-2)

        #if os(watchOS)
        #else
            switch name {
            case .attachment: ret = .attachment(validate(foundationValue))
            case .shadow: ret = .shadow(validate(foundationValue))
            default: break
            }
        #endif

        #if os(macOS)
            switch name {
            case .cursor: ret = .cursor(validate(foundationValue))
            case .markedClauseSegment: ret = .markedClauseSegment(validate(foundationValue))
            case .spellingState: ret = .spellingState(SpellingState(rawValue: validate(foundationValue))!)
            case .superscript: ret = .superscript(validate(foundationValue))
            case .textAlternatives: ret = .textAlternatives(validate(foundationValue))
            case .toolTip: ret = .toolTip(validate(foundationValue))
            default: break
            }
        #endif

        switch name {
        case .baselineOffset: ret = .baselineOffset(validateDouble(foundationValue))
        case .backgroundColor: ret = .backgroundColor(validate(foundationValue))
        case .expansion: ret = .expansion(validateDouble(foundationValue))

            let values: [Int] = validate(foundationValue)
            ret = .writingDirections(values.compactMap(WritingDirection.init))
        default:
            ret = .custom(name.rawValue, foundationValue)
        }

        self = ret
