Swift中Objective C类型定义的比较不起作用

时间:2014-11-25 09:20:14

标签: objective-c swift enums

我对飞利浦Hue SDK(在Swift中导入的Obj-C框架和桥接头)的枚举比较存在问题。

这是Obj-C enum:

/*******************************************************************************
 Copyright (c) 2013-2014 Koninklijke Philips N.V.
 All Rights Reserved.
 ********************************************************************************/

#define SDK_ERROR_DOMAIN @"com.philips.hue.sdk"

typedef enum {
    // Resource parsers
    INVALID_JSON = 1,
    INVALID_ARGUMENTS = 2,

    // PHHttpRequester
    NO_CONNECTION = 21,
    INVALID_PARAMETERS = 22,
    INVALID_PARAMETERS_MISSING_URL = 23,
    INVALID_PARAMETERS_MISSING_METHOD = 24,
    INVALID_PARAMETERS_INVALID_METHOD = 25,

    // Bridge Resource Cache Storage
    LIGHT_ID_NOT_FOUND = 41,
    SCHEDULE_ID_NOT_FOUND = 42,
    GROUP_ID_NOT_FOUND = 43,
    INVALID_DATA = 44,

    // Pushlinking
    PUSHLINK_NO_CONNECTION = 60,
    PUSHLINK_TIME_LIMIT_REACHED = 61,
    PUSHLINK_NO_LOCAL_BRIDGE = 62,

    // Unsupported
    UNSUPPORTED_IN_THIS_VERSION = 80,

    // Domain objects
    INVALID_DOMAIN_RESOURCE = 90,
    INVALID_DOMAIN_RESOURCE_ARGUMENT = 91,
    UNSUPPORTED_DOMAIN_RESOURCE_ARGUMENT = 92,

    CLIP_ERROR = 100
} CLErrorCode;

/**
    General purpose NSError derived object that is used for SDK errors
    Enum of error codes identifies error types
 */
@interface PHError : NSError

@end

在Obj-C示例项目中,他们比较了这样的枚举错误代码:

enter image description here

我的swift代码看起来像这样,我收到以下错误: enter image description here

我发现了这个问题:Equality on Objective-C typedef enum in Swift

但它不适合我。我已经试过......

error.code.value = PUSHLINK_NO_CONNECTION.value
error.code = PUSHLINK_NO_CONNECTION.value
error.code = .PUSHLINK_NO_CONNECTION
...

什么都没有用:(

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用rawValue? 像这样:

error.code.value == CLErrorCode.PUSHLINK_NO_CONNECTION. rawValue