Swift:CoreData 库中的断点 [英] Swift: Breakpoint in CoreData library

查看:12
本文介绍了Swift:CoreData 库中的断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Swift 的 XCode 6 Beta 3.

XCode 6 Beta 3 using Swift.

在我的应用程序中,我使用 CoreData.当我在模拟器中运行我的应用程序时,XCode 会弹出调试器,并在 CoreData 库中的某处设置断点(请参见屏幕截图).这发生在几个 CoreData 函数上,例如在插入新记录或从实体中获取记录时.断点位置始终相同.

In my App I use CoreData. When I run my App in simulator, XCode pops up the debugger with a breakpoint set somewhere in the CoreData library (see screenshot). This happens on several CoreData functions, for example when inserting new records or fetching records from an entity. The breakpoint position is always the same.

这太烦人了.当我的应用从实体获取 10 条记录时,我必须按 继续程序执行按钮 10 次.

This is extremely annoying. When my App fetches 10 records from an entity I have to push the continue program execution button 10 times.

因为这个断点是在机器代码的某个地方设置的,断点检查器没有显示任何断点,所以我不能删除它.

Because this breakpoint is set somewhere in machine code, the breakpoint inspector does not show any breakpoints so I cannot delete it.

有谁知道如何摆脱它?

非常感谢.

回溯输出:

(lldb) bt* 线程 #1: tid = 0x1d68b0, 0x000000010a2f7fcd libswift_stdlib_core.dylibswift_dynamicCastClassUnconditional + 77, queue = 'com.apple.main-thread', 停止原因 = EXC_BREAKPOINT (code=EXC_0xcode)* 第 0 帧:0x000000010a2f7fcd libswift_stdlib_core.dylibswift_dynamicCastClassUnconditional + 77帧 #1: 0x000000010a0fbb85 GPS TrackGPS_Track.TrackListTableViewController.tableView (tableView=)(Swift.ImplicitlyUnwrappedOptional<ObjectiveC.UITableView>, cellForRowAtIndexPath : Swift.Implicited>NSwrapIndex>Swift.Optional<ObjectiveC.UITableViewCell>+ 1125 在 TrackListTableViewController.swift:53帧 #2: 0x000000010a0fc937 GPS Track@objc GPS_Track.TrackListTableViewController.tableView (GPS_Track.TrackListTableViewController)(Swift.ImplicitlyUnwrappedOptional, cellForRowAtIndexPath : Swift.ImplicitlyUnwrappedOptional) -> 80 SwiftTableController at SwiftTableView第 3 帧:0x000000010bc2f218 UIKit-[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508第 4 帧:0x000000010bc0f340 UIKit-[UITableView _updateVisibleCellsNow:isRecursive:] + 2845第 5 帧:0x000000010bc24fea UIKit-[UITableView layoutSubviews] + 213第 6 帧:0x000000010bbb1ebd UIKit-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 519第 7 帧:0x000000010b9c9598 QuartzCore-[CALayer layoutSublayers] + 150帧 #8:0x000000010b9be1be QuartzCoreCA::Layer::layout_if_needed(CA::Transaction*) + 380帧 #9:0x000000010b9be02e QuartzCoreCA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24帧 #10:0x000000010b92cf16 QuartzCoreCA::Context::commit_transaction(CA::Transaction*) + 242帧 #11:0x000000010b92e022 QuartzCoreCA::Transaction::commit() + 390帧 #12:0x000000010b92e68d QuartzCoreCA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 89第 13 帧:0x000000010ab52927 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23第 14 帧:0x000000010ab52880 CoreFoundation__CFRunLoopDoObservers + 368第 15 帧:0x000000010ab480d3 CoreFoundation__CFRunLoopRun + 1123帧 #16:0x000000010ab47a06 CoreFoundationCFRunLoopRunSpecific + 470第 17 帧:0x000000010e9e9abf 图形服务<代码>GSEventRunModal + 161第 18 帧:0x000000010bb39cf8 UIKitUIApplicationMain + 1282帧 #19:0x000000010a0e6a5d GPS Tracktop_level_code + 77 在 AppDelegate.swift:36帧 #20:0x000000010a0e6a9a GPS Trackmain + 42 at AppDelegate.swift:0第 21 帧:0x000000010d2e7145 libdyld.dylib`start + 1(lldb)

(lldb) bt * thread #1: tid = 0x1d68b0, 0x000000010a2f7fcd libswift_stdlib_core.dylibswift_dynamicCastClassUnconditional + 77, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0) * frame #0: 0x000000010a2f7fcd libswift_stdlib_core.dylibswift_dynamicCastClassUnconditional + 77 frame #1: 0x000000010a0fbb85 GPS TrackGPS_Track.TrackListTableViewController.tableView (tableView=<unavailable>)(Swift.ImplicitlyUnwrappedOptional<ObjectiveC.UITableView>, cellForRowAtIndexPath : Swift.ImplicitlyUnwrappedOptional<ObjectiveC.NSIndexPath>) -> Swift.Optional<ObjectiveC.UITableViewCell> + 1125 at TrackListTableViewController.swift:53 frame #2: 0x000000010a0fc937 GPS Track@objc GPS_Track.TrackListTableViewController.tableView (GPS_Track.TrackListTableViewController)(Swift.ImplicitlyUnwrappedOptional, cellForRowAtIndexPath : Swift.ImplicitlyUnwrappedOptional) -> Swift.Optional + 87 at TrackListTableViewController.swift:0 frame #3: 0x000000010bc2f218 UIKit-[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508 frame #4: 0x000000010bc0f340 UIKit-[UITableView _updateVisibleCellsNow:isRecursive:] + 2845 frame #5: 0x000000010bc24fea UIKit-[UITableView layoutSubviews] + 213 frame #6: 0x000000010bbb1ebd UIKit-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 519 frame #7: 0x000000010b9c9598 QuartzCore-[CALayer layoutSublayers] + 150 frame #8: 0x000000010b9be1be QuartzCoreCA::Layer::layout_if_needed(CA::Transaction*) + 380 frame #9: 0x000000010b9be02e QuartzCoreCA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24 frame #10: 0x000000010b92cf16 QuartzCoreCA::Context::commit_transaction(CA::Transaction*) + 242 frame #11: 0x000000010b92e022 QuartzCoreCA::Transaction::commit() + 390 frame #12: 0x000000010b92e68d QuartzCoreCA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 89 frame #13: 0x000000010ab52927 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 frame #14: 0x000000010ab52880 CoreFoundation__CFRunLoopDoObservers + 368 frame #15: 0x000000010ab480d3 CoreFoundation__CFRunLoopRun + 1123 frame #16: 0x000000010ab47a06 CoreFoundationCFRunLoopRunSpecific + 470 frame #17: 0x000000010e9e9abf GraphicsServicesGSEventRunModal + 161 frame #18: 0x000000010bb39cf8 UIKitUIApplicationMain + 1282 frame #19: 0x000000010a0e6a5d GPS Tracktop_level_code + 77 at AppDelegate.swift:36 frame #20: 0x000000010a0e6a9a GPS Trackmain + 42 at AppDelegate.swift:0 frame #21: 0x000000010d2e7145 libdyld.dylib`start + 1 (lldb)

推荐答案

我进一步追踪了它:只有在为实体使用自定义对象类时才会出现问题.示例:

I tracked it down further: The problem only occurs when using custom object classes for the entities. Example:

// User class, defined in User.swift
class User: NSManagedObject {
    @NSManaged var name: String
    @NSManaged var firstname: String
}


// --------------
// code somewhere else
let users = moc.executeFetchRequest(fetchRequest, error: &error)

for object in users {
    let user = object as User   // <-- breakpoint fired here
        println(user.name)
    }
}

<小时>

解决方案:

需要使用@objc 指令使自定义对象类对目标 C 可见:

One need to make the custom object class visible to Objective C using the @objc directive:

// User class, defined in User.swift
@objc(User)    // <-- required!
class User: NSManagedObject {
    @NSManaged var name: String
    @NSManaged var firstname: String
}

感谢大家的帮助!

这篇关于Swift:CoreData 库中的断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆