zisoft
zisoft

Reputation: 23078

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)

Upvotes: 10

Views: 5181

Answers (8)

Penkey Suresh
Penkey Suresh

Reputation: 5974

For anyone using Xcode 6.2

  • Make @objc changes to your class i.e @objc(className)
  • Next go to *.xcdatamodeld -> Configurations (Default if nothing specified) -> add class against entity

Upvotes: 0

Viktor Hartlieb
Viktor Hartlieb

Reputation: 1

Following helped me ! If I undone one of this settings the breakpoint error comes again !

  1. You have to set for your Entity-Model in your *Model.xcdatamodeld in property "Class" the same Name example: Name=Chat Class=Chat

  2. You have to add Code @objc(yourClass) above your class

Pictures 1: https://i.sstatic.net/xoxtu.png

Pictures 2: https://i.sstatic.net/LkYYq.png

Upvotes: 0

Baub
Baub

Reputation: 5054

In your Core Data *.xcdatamodeld file, prefix your entity's class name with your app name. It should look something like this when you're done:

entity class name prefix

Upvotes: 2

Svitlana
Svitlana

Reputation: 3006

Thanks the last helped!!!

  • make the NSManagedObject-derived class and its relevant properties public
  • do not include its source file in the test target's Compile Sources
  • import the app target in the test file -- e.g., import MyApp in MyClassTests.swift

Upvotes: 0

Bob Mazanec
Bob Mazanec

Reputation: 1121

I fixed my version of this problem based on info in https://devforums.apple.com/message/1016337#1016337

  • make the NSManagedObject-derived class and its relevant properties public
  • do not include its source file in the test target's Compile Sources
  • import the app target in the test file -- e.g., import MyApp in MyClassTests.swift

Upvotes: 2

AppHandwerker
AppHandwerker

Reputation: 1788

While the above answers all are technically correct

@zisoft is right, however if you're using custom NSManagedObject classes then you should always use @objc(User), not just because of this break point.

@Zaph may work also, as you're essentially not listening and if indeed it's a bug it should stop it from appearing

However you may still hit this kind of break point if you're not type checking. I suspect it's a breakpoint in the beta 4 but will become a crash in the next beta.

I solved the issue in my code as I was hitting on returning the managed object received from insertNewObjectForEntityForName as AnyObject and later saying as myclass when I used it. Fine as I knew it was my class. but actualy should have done something like this

func createMyEntity() -> MyClass{ 
   if  let entity : MyClass = NSEntityDescription.insertNewObjectForEntityForName("MyClass", inManagedObjectContext: self.managedObjectContext) as? MyClass
    {
        return entity;
    } 
    return nil;
}

Obviously that's just one example, but if you're the hitting the break point in other places then hopefully this a good reference.

Not withstanding this still may just be a bug in beta 4 of xcode, but this is safer anyway.

Update -- It also checking that your data model class name matches as it later through a warning here an this may also be why the breakpoint was hit.

Upvotes: 2

zisoft
zisoft

Reputation: 23078

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!

Upvotes: 8

zaph
zaph

Reputation: 112875

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.

Upvotes: 2

Related Questions