I am having trouble using UndoManager with a private Manged Object Context in CoreData. Here is my setup: I have my main context running on the main queue. I created a private context via let privateContext = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType) and connect it as a child context to my main context via privateContext.parent = mainContext. I also assigned an UndoManager to privateContext. This UndoManger has been set to use manual grouping via undoManager.groupsByEvent = false. So far so good.
Now to the part that gives me trouble: I want to change something on the private context and record this action for potential undoing. In order to do this a use a nested grouping structure (that is how it makes sense in my code). This is how i currently do this:
privateContext.performAndWait {
undoManger.beginUndoGrouping
}
// do something in code unrelated to changes on the privateContext
privateContext.performAndWait {
doChangesOnPrivateContext()
}
privateContext.performAndWait {
undoManger.beginUndoGrouping
}
privateContext.performAndWait {
doChangesOnPrivateContext()
}
privateContext.performAndWait {
undoManger.endUndoGrouping
}
// do something in code unrelated to changes on the privateContext
privateContext.performAndWait {
undoManger.endUndoGrouping
}
This leads to the error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_setGroupIdentifier:: NSUndoManager is in invalid state, must begin a group before registering undo
which I had encountered before when beginUndoGrouping and endUndoGrouping were called from different threads. Further examination yields that this is also the case here as performAndWait runs the code on the private queue assigned to privateContext, but with the structure shown above beginUndoGrouping and endUndoGrouping are indeed called on different threads.
So here are my questions:
How do I do this correctly?
Do I misunderstand things and UndoMangager should not be used on a private context? If so, how would I setup things then?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,
I will be honest with you, I am quite confused on how to store additional content the right way using UIMangedDocument. Unfortunately the documentation on UIMangedDocument seems to be lacking a lot of information.
I am porting my UIDocument based app to a UIManagedDocument based app in order to make use of Core Data. In my UIDocument based approach I just stored additional data via overriding contents(forType:) to return a FileWrapper, which contains the appropriate structure and data like a Thumbnail.
Now it is my understanding, that in order to store additional data with UIManagedDocument you could override additionalContent(for:) which needs to return a Dictionary, not a FileWrapper. I want this to work with iCloud and Apple mentions in the documentation for additionalContent(for:): "Additional content isn’t supported on iCloud." So this does not seem to be the right approach for me.
I could of course store any additional data directly in Core Data's managed object context. But especially in the case of a thumbnail I think this is not the right approach because I would have to create a new UIMangedDocument, open it and then fetch the thumbnail from the persistent store every single time I just want to show a thumbnail for the document.
Also using thumbnailDictionaryKey and fileAttributesToWrite(to:for:) is not the right way as it is deprecated and I want to use the proper new way of a thumbnail extension for showing thumbnails of the documents.
So, what is the right way to store additional data like thumbnails in a UIManagedDocument in a way that is compatible with iCloud?
Hi,
I have the following simple view hierarchy, which is basically a scrollView with its contentView, which contains an imageView:
This imageView has a vector image assigned to its image property. The problem now is that when zooming with the scrollView the resolution of the image - the imageView displays - stays the same and the image is displayed blurry. This is of course expected behavior.
My question now is: what is the proper way to adjust the resolution of the displayed image in the imageView to scrollView.zoomScale?
I have a bunch of "workarounds" like setting a bigger frame for imageView and then scaling it down via its transform property, but those don't seem like the proper and intended way to do this. Any suggestions?
Is there any way to customize UIDocumentPickerViewController in terms of its visual appearance and additional actions for its menu?
I've seen some of these customization options for UIDocumentBrowserViewController, but none of them seems to be listed for UIDocumentPickerViewController in Apple's developer documentation.
Any hints are appreciated.