gpt4 book ai didi

ios - 此编码器要求从 initWithCoder : 返回替换的对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:05:27 24 4
gpt4 key购买 nike

我的应用程序在 iOS 11.2 中运行良好,但在 iOS 11.3 中会崩溃。我有异常(exception)

Terminating app due to uncaught exception 'NSGenericException', reason: 'This coder requires that replaced objects be returned from initWithCoder

我有一个带 tableView 的 viewController,这个 tableView 有 2 个单元格,不知何故,这个 TableView 无法在 cellForRowAtIndexPath 方法中加载一个单元格。

LPDiscoverFeedCell *cell = (LPDiscoverFeedCell *)[tableView dequeueReusableCellWithIdentifier:checkPortrait];

这是我得到这个的异常点。

最佳答案

Xcode 10.2 更新了具有新功能的编译器:

To reduce the size taken up by Swift metadata, convenienceinitializers defined in Swift now only allocate an object ahead oftime if they’re calling a designated initializer defined inObjective-C. In most cases, this has no effect on your app, but ifyour convenience initializer is called from Objective-C and doesn’t inturn delegate via self.init to an initializer exposed to Objective-C,the initial allocation from alloc is released without any initializerbeing called. This can be problematic for users of the initializerthat don’t expect any sort of object replacement to happen. Oneinstance of this is with initWithCoder:: the implementation ofNSKeyedUnarchiver may behave incorrectly if it calls into Swiftimplementations of initWithCoder: and the archived object graphcontains cycles. To avoid this, ensure that convenience initializersthat don’t support object replacement always delegate to initializersthat are also exposed to Objective-C, either because they’re definedin Objective-C, or because they’re marked with @objc, or because theyoverride initializers exposed to Objective-C, or because they satisfyrequirements of an @objc protocol. (46823518)"https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_release_notes/swift_5_release_notes_for_xcode_10_2?language=objc

我在 Storyboard 场景中有 MyClass:

enter image description here

如果 MyClass 有调用指定初始化器的 convenience init(),那么它应该用@objc 标记:

class MyClass: NSObject {
override convenience init() {
self.init(int: 42)
}

// Add @objc to stop crashes
@objc init(int: Int) {
super.init()
}
}

关于ios - 此编码器要求从 initWithCoder : 返回替换的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49654052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com