我刚刚将 Xcode 升级到 8.0 (8A218a),并将我在 Swift 2.3 中的项目转换为 Swift 3.0。现在剩下的唯一问题是这个错误:
“运行 ibtool 时出现异常:找不到名为 UTIToIconTransformer 的值转换器”
的UTIToIconTransformer
定义如下:
@objc(UTIToIconTransformer) class UTIToIconTransformer : ValueTransformer {
// ...
}
该代码在 Swift 2.3 中运行良好。使用此值转换器的绑定设置如下:
如果我删除此绑定,应用程序会运行,并且行标题会正确显示。
我已经尝试NSValueTransformer.setValueTransformer()
在应用程序委托中调用+initialize()
,在applicationDidFinishLaunching
值转换器中调用+initialize()
,如此处,在 StackOverflow 处和在 NShipster 处所建议的(虽然我不认为“通常,单例实例将在 +initialize值转换器子类的方法,因此无需进一步设置即可使用。”符合Apple的文档。),都没有成功。
在Apple 的文档中,它说
Value transformers are typically registered by an application’s delegate
class, in response to receiving a initialize: class message. This allows
registration to occur early in the application startup process, providing
access to the value transformers as nib files load.
Availability in Interface Builder
Your NSValueTransformer subclasses are not automatically listed in the
Interface Builder bindings inspector. When inspecting a binding you can enter
the name that the value transformer is registered with, but the functionality
will not be present in Interface Builder’s test mode. When your application
is compiled and run the transformer will be used.
但是在AppDelegate
's中注册override class func initialize()
并没有帮助。在 Xcode 7 和 Swift 2.3 中,它甚至可以在没有注册的情况下工作。