Swift 3中的Date._unconditionallyBridgeFromObjectiveC(NSDate?)崩溃 [英] Date._unconditionallyBridgeFromObjectiveC(NSDate?) crash in Swift 3
问题描述
我在一个快速文件中具有以下功能。我是从Obj C文件中使用NSDate代替startDate来调用的。而且很多时候,不是每次,我的应用都会崩溃
I have following function in a swift file. I am calling this from Obj C file with NSDate in place of startDate. And quite often, not every time, my app crashes with
Date._unconditionallyBridgeFromObjectiveC(NSDate?)
Date._unconditionallyBridgeFromObjectiveC(NSDate?)
我该如何解决?
func trackMeetingEnded(_ name: String, startDate: Date, backgroundTime: TimeInterval) {}
堆栈跟踪
Crashed: com.apple.main-thread
0 libswiftFoundation.dylib 0x102061e98 static Date._unconditionallyBridgeFromObjectiveC(NSDate?) -> Date + 72
1 Acid 0x10017ece4 @objc static ClusteredMixpanel.trackMeetingEnded(String, startDate : Date, backgroundTime : Double) -> () (MixpanelMeeting.swift)
2 Acid 0x10073e1bc __56-[MeetingLifeCycleViewController stateInitialization]_block_invoke.221 (MeetingLifeCycleViewController.m:267)
3 Acid 0x1001ee5c4 partial apply for thunk (StateMachine.swift)
4 Acid 0x1001ea70c specialized State.willLeaveState(State) -> () (StateMachine.swift:238)
5 Acid 0x1001ead90 specialized StateMachine.transitionToState(State) -> Bool (StateMachine.swift)
6 Acid 0x1001e1f18 @objc StateMachine.transitionToState(State) -> Bool (StateMachine.swift)
7 Acid 0x10073ace0 -[MeetingLifeCycleViewController dismissCall] (MeetingLifeCycleViewController.m:538)
8 Acid 0x10086d648 -[InMeetingViewController hangup] (InMeetingViewController.m:531)
在这种情况下,我相信NSDate到Date的转换是由OS完成的。仅在迁移到Swift 3之后才能看到该问题。是否存在任何已知问题?我在网上找不到任何东西:(
I believe NSDate to Date conversion is done by OS in this case. The issue is seen only after migration to Swift 3. Are there any known issues around this? I could not find anything online :(
推荐答案
您可能需要仔细检查 NSDate 来自Objective-C的code>实际上不是-
nil
,因为没有什么东西可以像Swift一样有效地强制Obj-C方面
You probably need to double check that the NSDate
coming from Objective-C is actually non-nil
, since there's nothing that's actively enforcing that on the Obj-C side the way there is on the Swift side.
我最终将尽可能多的 Date
转换为 Date?
s就像我从Obj-C处被叫到一样,然后进行了很多后卫检查
检查。
I wound up converting as many Date
s to Date?
s as I could find being called from Obj-C, then doing a whole lot of guard let
checks.
在开发过程中,您还可以抛出 assertionFailure
对您大喊大叫,以了解那些 nil
的位置您不期望的日期来自。例如:
You can also throw in an assertionFailure
to yell at you when you're in development about where those nil
dates you're not expecting are coming from. For example:
guard let date = passedInDate else {
assertionFailure("Turns out the passed-in date was nil!")
return
}
然后查看一下堆栈跟踪,当它被击中时,是否可以更好地了解为什么在那里获得意外的 nil
值。
Then take a look at your stack trace when that gets hit to see if you can get a better grip on why you're getting an unexpected nil
value there.
更新:这是在Swift源代码中发生崩溃的位置。
Update: Here's where the crash is occurring in the Swift source code.
这篇关于Swift 3中的Date._unconditionallyBridgeFromObjectiveC(NSDate?)崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!