gpt4 book ai didi

objective-c - Swift 中 Objective C typedef 枚举的比较不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 05:42:19 24 4
gpt4 key购买 nike

我对 Philips Hue SDK 的枚举比较有问题(在 Swift 中导入带有桥头的 Obj-C 框架)。

这是 Obj-C 枚举:

/*******************************************************************************
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

我发现了这个 SO 问题: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
...

没有任何效果:(

最佳答案

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

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

关于objective-c - Swift 中 Objective C typedef 枚举的比较不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27122782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com