             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 {
+        let ret: Attribute
+
+        switch name {
+        #if !os(watchOS)
             case .attachment: ret = .attachment(validate(foundationValue))
             case .shadow: ret = .shadow(validate(foundationValue))
-            default: break
-            }
-        #endif
-
-        #if os(macOS)
-            switch name {
+        #endif
+        #if os(macOS)
             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 {
+        #endif
         case .baselineOffset: ret = .baselineOffset(validateDouble(foundationValue))
         case .backgroundColor: ret = .backgroundColor(validate(foundationValue))
         case .expansion: ret = .expansion(validateDouble(foundationValue))

    // Convenience getter variable for the associated value of the attribute. See each case to determine the return type.
    public var value: Any {

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

        #if os(watchOS)
        #else
            switch self {
            case .attachment(let attachment): return attachment
            case .shadow(let shadow): return shadow
            default: break
            }
        #endif

        #if os(macOS)
            switch self {
            case .cursor(let cursor): return cursor
            case .markedClauseSegment(let segment): return segment
            case .spellingState(let state): return state
            case .superscript(let superscript): return superscript
            case .textAlternatives(let alternatives): return alternatives
            case .toolTip(let text): return text
            default: break
            }
        #endif

        switch self {
        case .baselineOffset(let offset): return offset
        case .backgroundColor(let color): return color
        case .expansion(let expansion): return expansion


    /// The key name corresponding to the attribute.
    public var keyName: NSAttributedString.Key {
        let name: NSAttributedString.Key

        switch self {
        #if !os(watchOS)
            case .attachment: name = .attachment
            case .shadow: name = .shadow
        #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
        #endif
        case .baselineOffset: name = .baselineOffset
        case .backgroundColor: name = .backgroundColor
        case .expansion: name = .expansion
