NSManagedObjectContext and undoManager on macOS

HI,

it looks like when creating a new instace of an NSManagedObjectContext on macOS its undoManager property doesn't get set automatically as before, but rather it now has the same behavior as in iOS and it' set to nil by default.

Can anyone confirm this behavior? The NSManagedObjectContext official documentation (undoManager property section) still report that under macOS this property gets automatically set with an NSUndoManager instance.

Replies

I see the same thing. Sad that the documentation was not updated and the behavior was changed under the app.

I think you are right, and the documentation is not updated:


From the docs:


In macOS, a context provides an undo manager by default; on iOS, the undo manager is nil by default.


I create a Cocoa app with CoreData and put a breakpoint in return managedObjectContext:


    lazy var managedObjectContext: NSManagedObjectContext = {
        let coordinator = self.persistentStoreCoordinator
        var managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
        managedObjectContext.persistentStoreCoordinator = coordinator

        return managedObjectContext
    }()


When the breakpoint is hit I wrote in the console:


po managedObjectContext.undoManager

And it returns nil.

Also in the definition of NSManagedObjectContext for Cocoa, undoManager is defined as optional, which default value is nil.


@available(OSX 10.4, *)
open class NSManagedObjectContext : NSObject, NSCoding, NSLocking {

open var undoManager: UndoManager?