从Swift类访问Objective-c基类的实例变量 [英] Accessing Objective-c base class's instance variables from a Swift class
本文介绍了从Swift类访问Objective-c基类的实例变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
拥有Objective c基类:
Having an Objective c base class:
@interface ObjcClass : NSObject {
NSString *aVariable_;
}
快速的子类:
class SwiftClass : ObjcClass {
func init() {
// aVariable_ can't be accessed here. An Objective-c derived
// class has direct access to it's super's instance variables!
}
}
如何访问 ObjcClass
aVariable _
来自 SwiftClass
?
推荐答案
很棒的查询。我们努力完成这项工作。我找到的唯一可行解决方案
Great query. We have tried to hard to get this done. The only working solution I found
使用 self.valueForKey(aVariable _)获取价值
使用设置值self.setValue(新值,forKey:aVariable _)
希望有所帮助。在不改变超类的情况下可能的解决方案。
Hope that helps. Possible solution without altering super class.
这篇关于从Swift类访问Objective-c基类的实例变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文