我想以 SwiftUIText
视图的形式返回一个UnsafeMutableRawPointer
,遵守 C 调用约定,以便另一种语言可以 FFI 进入它以供使用。
@_cdecl("hi")
func hi (txt: UnsafeMutablePointer<CChar>) -> () {
var view = ViewBuilder.buildBlock(Text(String(cString: txt)))
return UnsafeMutableRawPointer(Unmanaged.passUnretained(view).toOpaque())
}
但我收到以下错误:
Cannot invoke 'passUnretained' with an argument list of type '(Text)'
如何获取 SwiftUIText
对象的底层指针?