Avn*_*arr 5 struct objective-c ios swift objective-c-swift-bridge
我有一个swift方法接收结构作为参数。由于未将结构桥接到Objective-C,因此此方法在桥接标头中不可见。
我被迫创建一个新的“完全相同”的方法,该方法接收“ AnyObject”而不是结构所要求的原始方法。
现在,我负责从“ AnyObject” 实例化swift结构。是否可以“投射”“AnyObject在这种情况下, ”转换为快速结构?
我是否被迫编写样板文件以从中构造一个快速结构 AnyObject?
我可以寄一个 NSDictionary表示结构的键/值对。这有什么帮助吗?
例如 :
迅速
struct Properties {
var color = UIColor.redColor()
var text = "Some text"
}
class SomeClass : UIViewController {
func configure(options : Properties) {
// the original method
// not visible from
}
func wrapObjC_Configure(options : AnyObject) {
// Visible to objective-c
var convertedStruct = (options as Properties) // cast to the swift struct
self.configure(convertedStruct)
}
}
Run Code Online (Sandbox Code Playgroud)
目标c
SomeClass *obj = [SomeClass new]
[obj wrapObjC_Configure:@{@"color" : [UIColor redColor],@"text" : @"Some text"}]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3725 次 |
| 最近记录: |