我有包含自定义对象的 XIB,其中一个实际上是一个类集群,其-init
方法总是返回相同的单例对象。
基本上:
- (instancetype)init
{
self = [super init];
if (HelpLinkHelperSingleton==nil)
{
// This is the first instance of DDHelpLink: make it the immortal singleton
HelpLinkHelperSingleton = self;
}
else
{
// Not the first DDHelpLink object to be created: discard this instance
// and return a reference to the shared singleton
self = HelpLinkHelperSingleton;
}
return self;
}
从 macOS 12.0.1 开始,加载 XIB 会引发此异常:
This coder is expecting the replaced object 0x600002a4f680 to be returned from NSClassSwapper.initWithCoder instead of <DDHelpLink: 0x600002a487a0>
我尝试实施<NSSecureCoding>
并做同样的事情,但这也不起作用。
还有一种方法可以在 NIB 中使用类集群吗?