[英]enum defined in Objc > Declared in Swift > to be used in Objc
I have a situation. 我有情况 I would appreciated if anyone has a solution for this
如果有人对此有解决方案,我将不胜感激
enum
say Abc
enum
说Abc
MySwiftClass.swift
as var abc : Abc!
MySwiftClass.swift
为var abc : Abc!
mySwiftClass
) in another ObjC class (myObjC.m file) mySwiftClass
)的实例。 mySwiftClass.abc
. mySwiftClass.abc
身份访问枚举Abc。 This is throwing an error - “Property 'abc' not found on object of type MySwiftClass *”. 这将引发错误-“在MySwiftClass *类型的对象上找不到属性'abc'。 Basically the enum is not added as property in the “ProjectName-Swift.h” file.
基本上,枚举不作为属性添加到“ ProjectName-Swift.h”文件中。
What I believe is happening is that when I'm declaring the ObjC enum in Swift class, it is getting converted to a swift enum and hence I'm not able to access it in ObjC file. 我相信正在发生的事情是,当我在Swift类中声明ObjC枚举时,它已转换为swift枚举,因此无法在ObjC文件中访问它。
Note: Marking the Swift class as @objc did not work. 注意:将Swift类标记为@objc无效。
Numeric Swift optionals cannot be represented in Objective-C, and thus will not be exposed to Objective-C. Swift中的数字可选内容无法在Objective-C中表示,因此不会暴露于Objective-C。 Declare
abc
to not be optional and it should be available from Objective-C. 声明
abc
不是可选的,应该可以从Objective-C获得。
Consider this Objective-C enumeration: 考虑以下Objective-C枚举:
typedef NS_ENUM(NSInteger, Foo) {
FooBar,
FooBaz,
FooQux
};
Then consider this Swift 3 class: 然后考虑这个Swift 3类:
class SomeObject: NSObject {
var foo1: Foo = .bar // this is exposed to Objective-C
var foo2: Foo! = .bar // this is not
}
The non-optional, foo1
, will be exposed to Objective-C, whereas the optional, foo2
, will not. 非可选的
foo1
将公开给Objective-C,而可选的foo2
则不会公开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.