Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Breakpoint in CoreData library

XCode 6 Beta 3 using Swift.

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.

enter image description here

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.

Does anyone know how to get rid of it?

Many thanks.


Edit: backtrace-output:

(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)

like image 455
zisoft Avatar asked Jul 19 '14 15:07

zisoft


People also ask

Could not merge changes CoreData?

Problem: You see the error message, " Could not merge changes ." Cause: Two different managed object contexts tried to change the same data. This is also known as an optimistic locking failure. Remedy: Either set a merge policy on the context, or manually (programmatically) resolve the failure.

Where is core data stored?

The persistent store should be located in the AppData > Library > Application Support directory.

How do I get NSManagedObject?

To do that, go to the Editor menu and choose Create NSManagedObject Subclass, make sure “CoreDataProject” is selected then press Next, then make sure Movie is selected and press Next again.

How can you retrieve data from core data?

Fetching Data From CoreData We have created a function fetch() whose return type is array of College(Entity). For fetching the data we just write context. fetch and pass fetchRequest that will generate an exception so we handle it by writing try catch, so we fetched our all the data from CoreData.


2 Answers

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)
    }
}

SOLUTION:

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
}

Thanks to all for your help!

like image 130
zisoft Avatar answered Oct 28 '22 09:10

zisoft


Do you have an All Exception breakpoint set?

enter image description here

Contrary to Apple's best practices CoreData uses exceptions in the normal flow of control.

If you add exception breakpoints you may break in CoreData. The solution is to remove or disable the exception breakpoint.

like image 21
zaph Avatar answered Oct 28 '22 10:10

zaph