我遇到了今天困扰着任何Apple开发人员的错误代码EXC_BAD_ACCESS
..经过大量的研究,以各种不同的调试方法等,我来到了这里。
更新:如果有人愿意帮助解决此问题,https://github.com/TheRiseCollection/sway
是这里的GitHub库链接。在Xcode中打开zombie objects
告诉我nil
处的guard let view = nib.instantiate(withOwner: self, options: nil).first as? T
引起了我的问题Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeec121e98)
下面是完整文件NibView.swift
//Joshua Paulsen - The Rise Collection
import UIKit
/// A base UIView subclass that instaniates a view
/// from a nib file of the same class name in order to
/// allow reusable views to be created.
internal protocol NibView where Self: UIView {
}
extension NibView {
/// Initializes the view from a xib
/// file and configure initial constrains.
func xibSetup() {
backgroundColor = .clear
let view = loadViewFromNib()
addEdgeConstrainedSubView(view: view)
}
/// Loads a view from it's xib file.
///
/// - Returns: an instantiated view from the Nib file of the same class name.
fileprivate func loadViewFromNib<T: UIView>() -> T {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
guard let view = nib.instantiate(withOwner: self, options: nil).first as? T else {
fatalError("Cannot instantiate a UIView from the nib for class \(type(of: self))")
}
return view
}
}
我刚开始接触笔尖视图!在此处寻求解决方案,我们将不胜感激。
答案 0 :(得分:0)
具有自定义类,已将其分配给我所拥有的每个视图,从而导致此EXC_BAD_ACCESS错误触发。
删除它们使它停止了。让我们继续解决这个臭名昭著的EXC_BAD_ACCESS错误。谢谢大家的帮助。
答案 1 :(得分:0)
EXC_BAD_ACCESS错误的另一个原因是在NSNotificationCenter中从收到通知时调用的函数发送通知。