不强制展开时的EXC_Breakpoint [英] EXC_Breakpoint when not forcefully unwrapping
问题描述
我遇到崩溃 EXC_Breakpoint
,这向我表明有一个 nil
变量被解包了吗?
I'm getting a crash EXC_Breakpoint
which would indicate to me that there is a nil
variable being unwrapped?
它指向的代码行是let obHeight 的定义:
The line of code it is pointing to is the definition of let obHeight:
if let qs = Helper_Question.getSection(sid: self.sections[0].sid) {
let obEnabled = Helper_Type.getId(id: tid)?.enableObservation == 1
for q in qs {
let ans = Helper_Answer.getQuestion(aid: selectedAid!, qid: q.Id)
var baseHeight : CGFloat = 300
switch(q.qtype){
case Constants.DEFAULT:
let obHeight : CGFloat = (obEnabled || ans?.comment != "" || (ans?.answer == "1" && q.hasChildren == 0) || (ans?.answer == "2" && q.hasChildren == 0)) && ans?._na == 0 ? 40 : 0
....
}
}
}
我正在使用?
而不是强制展开,所以我不认为这是问题所在?该崩溃报告今天发布,但是我无法在任何设备上复制它。除了 nil
变量之外,还有什么其他原因会导致 EXC_Breakpoint
崩溃?在表视图单元格中单击按钮时会调用此代码,并使用委托在呈现splitviewcontroller之前调用此代码进行一些计算。 selectedAid始终来自按钮的可访问性标识符,我一直在行的单元格中设置该标识符。它不是nil
I'm using the ?
instead of forcefully unwrapping so I don't think this is the issue? This crash report came into today but I cannot reproduce it on any device. What other reason apart from a nil
variable would cause a EXC_Breakpoint
crash? This code is called on action of a button click in a table view cell and uses a delegate to call this code to do some calculations before presenting a splitviewcontroller. selectedAid comes from the button's accessibility identifier which i am setting in the cell for row, always. it is not nil
崩溃日志:
Crashed: com.apple.main-thread
0 AppName 0x100664b30 specialized AuditVC.editBtnTapped(cell : PendingAuditTVC) -> () (AuditVC.swift:294)
1 AppName 0x10065fa68 AuditVCAppNamePendingAuditCellDelegate (AuditVC.swift)
2 AppName 0x100717468 PendingAuditTVC.editTapped(Any) -> () (PendingAuditTVC.swift:41)
3 AppName 0x100717648 @objc PendingAuditTVC.editTapped(Any) -> () + 4302730824
4 UIKit 0x1907c6010 -[UIApplication sendAction:to:from:forEvent:] + 96
5 UIKit 0x1907c5f90 -[UIControl sendAction:to:forEvent:] + 80
6 UIKit 0x1907b0504 -[UIControl _sendActionsForEvents:withEvent:] + 440
7 UIKit 0x1907c5874 -[UIControl touchesEnded:withEvent:] + 576
8 UIKit 0x190d5a550 _UIGestureEnvironmentSortAndSendDelayedTouches + 4280
9 UIKit 0x190d5689c _UIGestureEnvironmentUpdate + 1128
10 UIKit 0x190d563e0 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 404
11 UIKit 0x190d5568c -[UIGestureEnvironment _updateGesturesForEvent:window:] + 268
12 UIKit 0x1907c070c -[UIWindow sendEvent:] + 3164
13 UIKit 0x19079133c -[UIApplication sendEvent:] + 340
14 UIKit 0x190f8b014 __dispatchPreprocessedEventFromEventQueue + 2400
15 UIKit 0x190f85770 __handleEventQueue + 4268
16 UIKit 0x190f85b9c __handleHIDEventFetcherDrain + 148
17 CoreFoundation 0x18a61542c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
18 CoreFoundation 0x18a614d9c __CFRunLoopDoSources0 + 540
19 CoreFoundation 0x18a6129a8 __CFRunLoopRun + 744
20 CoreFoundation 0x18a542da4 CFRunLoopRunSpecific + 424
21 GraphicsServices 0x18bfac074 GSEventRunModal + 100
22 UIKit 0x1907f6058 UIApplicationMain + 208
23 AppName 0x100044590 main (AppDelegate.swift:23)
24 libdyld.dylib 0x18955159c start + 4
更新
open class Question
{
open var Id : Int = 0
open var sectionid : Int = 0
open var question : String = ""
open var hasChildren : Int = 0
open var qtype : Int = 0
open var defaultValue : String = ""
}
public class UP_IA_Answer_m : EVObject {
public var localId : String = ""
public var aid : String = ""
public var sid : Int = 0
public var qid : Int = 0
public var answer : String = ""
public var comment : String = ""
public var hasChildren : Int = 0
public var _na : Int = 0
}
推荐答案
用 x替换单线的值和变量名,以便更容易发现错误:
Replacing the values and variable names of the one-liner with "x" to make the error easier to spot:
(x || x?.x!= x || (x?.x == x& x == x)|| (x?.x == x& x == x))&& x?.x == x? x:x
(x || x?.x != x || (x?.x == x && x == x) || (x?.x == x && x == x)) && x?.x == x ? x : x
我认为很清楚错误发生在哪里。
I think it is pretty clear where the error happens.
这篇关于不强制展开时的EXC_Breakpoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!