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.
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.dylib
swift_dynamicCastClassUnconditional + 77, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0) * frame #0: 0x000000010a2f7fcd libswift_stdlib_core.dylib
swift_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 QuartzCore
CA::Layer::layout_if_needed(CA::Transaction*) + 380 frame #9: 0x000000010b9be02e QuartzCoreCA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24 frame #10: 0x000000010b92cf16 QuartzCore
CA::Context::commit_transaction(CA::Transaction*) + 242 frame #11: 0x000000010b92e022 QuartzCoreCA::Transaction::commit() + 390 frame #12: 0x000000010b92e68d QuartzCore
CA::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 CoreFoundation
CFRunLoopRunSpecific + 470 frame #17: 0x000000010e9e9abf GraphicsServicesGSEventRunModal + 161 frame #18: 0x000000010bb39cf8 UIKit
UIApplicationMain + 1282 frame #19: 0x000000010a0e6a5d GPS Tracktop_level_code + 77 at AppDelegate.swift:36 frame #20: 0x000000010a0e6a9a GPS Track
main + 42 at AppDelegate.swift:0 frame #21: 0x000000010d2e7145 libdyld.dylib`start + 1 (lldb)
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.
The persistent store should be located in the AppData > Library > Application Support directory.
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.
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.
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!
Do you have an All Exception breakpoint set?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With