快速调用以枚举为参数的目标c方法

时间:2018-08-24 17:27:20

标签: objective-c swift enums

我试图在swift中使用带有enum作为参数的客观c方法。该参数的值是根据swift枚举变量设置的。

快速枚举

enum SecurityType: Int {

    case pushNotification = 0
    case touchId = 1
    case faceId = 2
}

我在目标c文件中的枚举看起来像

typedef NS_ENUM(NSUInteger, ScreenType) {
TouchID = 1,
FaceID = 2,
ConsentApproval = 3,
VerifyMyIdentity = 4 };

我的快捷代码是

let screenType: ScreenType = self.biometricType == .touchId ? .touchID : .faceID

guard let newVC = MyViewController.init(screenType: screenType) else { return }

在上述方法中, biometricType 变量为快速枚举类型。

这是我的初始化方法

-(instancetype)initWithScreenType:(screenType *)type {

self = [super init];

  if (self) {
     UIStoryboard *passcodeStoryBoard = [UIStoryboard  storyboardWithName:passcode bundle:nil];
     self = [passcodeStoryBoard  instantiateViewControllerWithIdentifier:@"AuthenticationViewController"];
     self.screenType = type;
     return self;
  }

返回零; }

我在初始化方法上遇到错误

  

无法将类型“ EnumType”的值转换为预期的参数类型“ UnsafeMutablePointer!”

有人知道它背后的原因是什么吗?

1 个答案:

答案 0 :(得分:0)

首先,self.biometricType的类型为UnsafeMutablePointer。 您无法将UnsafeMutablePointer类型设置为枚举ScreenType

第二,您应该使用完整的枚举名称来访问obj-c枚举,例如本示例。

let screenType: ScreenType = ScreenType.TouchId
相关问题