nsmanagedobjectcontext

how do you create a NSManagedObjectContext

僤鯓⒐⒋嵵緔 提交于 2019-11-30 10:06:20
In core data for the iPhone, I was getting all sorts of errors trying to save data to a NSManagedObjectContext . I believe that my issues were all to do with me using a NSManagedObjectContext that was being used in multiple threads. So I wanted to create a new NSManagedObjectContext and try that, but I cannot find the example code to simply create a new instance... I know its simple, but I would really appreciate any help here. Note, I have seen this article on the Apple docs: http://developer.apple.com/iphone/library/documentation/cocoa/conceptual/CoreDataUtilityTutorial/Articles/05

How to use CoreData in Xcode 8?

安稳与你 提交于 2019-11-30 05:27:10
I am trying use CoreData, but when I add it to my project I only get two new methods : - (NSPersistentContainer *)persistentContainer and - (void)saveContext Now I can't get old methods to work with CoreData , and I can't find any tutorials with these new methods and Objective-C. How can I save and get data from CoreData using persistentContainer in Xcode 8 with Objective-c? You can Get context as - let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext or as in Objective-C NSManagedObjectContext *context = ((AppDelegate*)[[UIApplication sharedApplication

Create an NSManagedObject Without Saving? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-11-30 05:14:34
Possible Duplicate: Store But Don't Save NSManagedObject to CoreData? I need to make an NSManagedObject without saving it, how can I do this? The reason I want to do this is the app has a setup in which the user enters their details, however I only want to save the object if they complete the setup (they have the option to cancel, in which case the object needs to be discarded without being saved, which is why I don't want to insert it straight away). I have tried insetting one without a context but the app crashes. I have tried the following: GuestInfo *guest; guest = (GuestInfo *)

How to handle cleanup of external data when deleting *unsaved* Core Data objects?

半世苍凉 提交于 2019-11-30 04:36:09
问题 In a managed object i have stored a path to an image file in the application's container. When the managed object get’s deleted, the image file should be moved to trash. This should be done as late as possible, so that i can provide undo functionality for as long as possible. I was following the answers of this question: How to handle cleanup of external data when deleting Core Data objects, and was overriding -didSave in my managed object subclass to trash the files. Turns out, this works

Core Data: parent context blocks child

我的梦境 提交于 2019-11-29 21:16:47
问题 I'm doing some background processing in an app with core data. The background processing is done on a child managedObjectContext. Context initialization: appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate // the moc in appDelegate is created with .MainQueueConcurrencyType mainThreadMOC = appDelegate.managedObjectContext! backgroundMOC = NSManagedObjectContext(concurrencyType:NSManagedObjectContextConcurrencyType.PrivateQueueConcurrencyType) backgroundMOC?.parentContext =

When to use Core Data's NSMainQueueConcurrencyType?

為{幸葍}努か 提交于 2019-11-29 20:10:05
Is initializing a NSManagedObjectContext using NSMainQueueConcurrencyType only for the situation where that MOC has a child MOC that was initialized using NSPrivateQueueConcurrencyType ? To give some background: my app has a traditional structure whereby the main table view is driven by a NSFetchedResultsController and data are imported asynchronously from a web service using an NSOperation subclass that has its own MOC. I wasn't sure whether both MOCs in that situation should use NSConfinementConcurrencyType (the default, I believe) or whether the MOC associated with the fetched results

How can I track/observe all changes within a subgraph?

倖福魔咒の 提交于 2019-11-29 18:47:21
I have a NSManagedObjectContext in which I have a number of subclasses of NSManagedObjects such that some are containers for others. What I'd like to do is watch a top-level object to be notified of any changes to any of its properties, associations, or the properties/associations of any of the objects it contains. Using the context's 'hasChanges' doesn't give me enough granularity. The objects 'isUpdated' method only applies to the given object (and not anything in its associations). Is there a convenient (perhaps, KVO-based) was I can observe changes in a context that are limited to a

Debugging SIGABRT within NSManagedObjectContext -save:

做~自己de王妃 提交于 2019-11-29 12:08:12
问题 From inside NSManagedObjectContext -save: I am getting this message: Assertion failed: (_Unwind_SjLj_Resume() can't return), function _Unwind_SjLj_Resume, file /SourceCache/libunwind/libunwind-24.1/src/Unwind-sjlj.c, line 326. Program received signal: “SIGABRT”. warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found). This happens when I delete an Experiment object with to

How to use CoreData in Xcode 8?

无人久伴 提交于 2019-11-29 03:52:44
问题 I am trying use CoreData, but when I add it to my project I only get two new methods : - (NSPersistentContainer *)persistentContainer and - (void)saveContext Now I can't get old methods to work with CoreData , and I can't find any tutorials with these new methods and Objective-C. How can I save and get data from CoreData using persistentContainer in Xcode 8 with Objective-c? 回答1: You can Get context as - let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer

Create an NSManagedObject Without Saving? [duplicate]

人盡茶涼 提交于 2019-11-29 03:05:28
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Store But Don't Save NSManagedObject to CoreData? I need to make an NSManagedObject without saving it, how can I do this? The reason I want to do this is the app has a setup in which the user enters their details, however I only want to save the object if they complete the setup (they have the option to cancel, in which case the object needs to be discarded without being saved, which is why I don't want to