ios - Fatal error: could not demangle keypath type
问题描述
I have a simple class and I want to use keypath in the init
, something like this:
class V: UIView {
convenience init() {
self.init(frame: .zero)
self[keyPath: \.alpha] = 0.5
}
}
let v = View()
When I run this code I get a runtime error:
Fatal error: could not demangle keypath type from ' ����XD':
But, if I specify the type in keyPath it works fine:
class V: UIView {
convenience init() {
self.init(frame: .zero)
self[keyPath: \UIView.alpha] = 0.5
}
}
let v = View()
print(v.alpha) \\ prints 0.5
But, what's even stranger is that this code works:
class V: UIView {
convenience init() {
self.init(frame: .zero)
foo()
}
func foo() {
self[keyPath: \.alpha] = 0.5
}
}
let v = View()
print(v.alpha) \\ prints 0.5
What is the actual reason for this error?
解决方案
推荐阅读
- python - 是否有任何方法/技术可以提高 python numpy 中的矩阵乘法速度
- javascript - PHP V8 JS 未执行但页面未中断且未显示错误
- python - 使用 MongoDB Atlas 部署烧瓶 Web 应用程序时出错
- oracle-sqldeveloper - 我们可以在 Snowflake 中使用类似于 Oracle SQL 的表声明吗?
- r - 如何关联R中的多个子集
- javascript - Electron 8 printToPdf pageSize 始终测量相同
- html - 如何仅使用 css 添加内容并为其添加颜色
- postgresql - 无法连接到 Google 云上的 Postgres 数据库实例
- vue.js - 为什么在 VSCode 中调试 VueJS 如此不稳定
- r - 为什么 `full_join` 有重复时会增加行数?