0

我刚刚将 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 中,它甚至可以在没有注册的情况下工作。

4

1 回答 1

0

最后我通过NSOutlineView从情节提要中删除并设置一个新的来解决问题。我有另一个项目,它也有一个与 绑定的大纲视图NSTreeController,并且该项目在 Xcode 8.0 升级后没有问题。然后我尝试ValueTransformer用新名称创建一个新名称,但没有运气。我猜故事板可能有问题,所以我尝试重新创建大纲视图。然后 Xcode 就不会抱怨找不到转换器了!

于 2016-09-16T06:41:41.843 回答