Why can I not use KVC from an Objective-C object to a Swift Property?

不羁岁月 提交于 2019-12-05 04:59:33

The reason is that a Swift optional struct or enum (in your case CGFloat?) is not representable in Objective-C (and you won't see that property in the generated "Project-Swift.h" header file). That becomes more obvious if you mark the property explicitly with @objc, then you'll get the error message

error: property cannot be marked @objc because its type cannot be represented in Objective-C

If you change the property type to the non-optional CGFloat then KVC works as expected. It would also work with an optional class type, such as NSNumber?.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!