I use the a helper class to get a block with NSManagedObjectContext in it.
+ (void)openTheDocumentAndPerformBlock:(completion_handle_t)completionBlock;
And now I want to keep one of the NSManagedObject outside of the block, because I want to interact with it constantly. And if I can’t keep it in the ViewController, I have to query it everytime when I need it, and it will be really troublesome.
1, And can I pass the NSManagedObject through segue to another VC?
2, does the UIManagedDocument has to be open all the time when those thing append?
3, And Can I edit the NSManagedObject outside of the block, and save it in the Block?
If I am understanding your question correctly, you just need an instance variable of type
NSManagedObjectin your class(the view controller class) so that you can assign your managed object, that you queried out in your block to this variable. You can use this wherever you want.As for your other questions:
1. Hope the following code snippet works:
In your destination view controller class declare an instance variable to store the passed object.
inside the
prepareForSegue:method of source view controller get the destination vc and pass the managed object:And yes you can use NSManagedObject inside and outside your block as long its the same managed object context you are using.
And I don’t know the answer for your second question.