Re: Swift - Basic query regarding managedObjectContext method invocation from app delegate
> On 2014 Oct 14, at 22:27, Devarshi Kulshreshtha > wrote: > > I know about NSBatchUpdateRequest Yes, that’s what I was thinking of. How about the reset + save ? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Swift - Basic query regarding managedObjectContext method invocation from app delegate
I know about NSBatchUpdateRequest and NSAsynchronousFetchRequest, is there any other fun part in modern world which can help me in my requirement, excited to know ;) On Wed, Oct 15, 2014 at 1:13 AM, Jerry Krinock wrote: > >> On 2014 Oct 14, at 05:42, Devarshi Kulshreshtha >> wrote: >> >> I am trying to implement reset functionality in core data based sample app. >> >> I think that there are two ways to implement reset functionality: >> >> Approach 1: Delete sqlite file and then re-insert data > > As you’ve seen, this is tricky to do without relying on some > Apple-impleentation-dependent behaviors. > >> Approach 2: Retrieve all data in managedObjectContext, delete >> retrieved data and then re-insert data > > Performance may be unacceptable, and people will disrespect your code :) > > * * * > > How about a third approach: perform a managed object context reset(), > followed by a save(). Does that work? > > Finally, if you’re in the modern world of Yosemite or iOS8, maybe some of the > new direct database access methods will do what you want. > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/devarshi.bluechip%40gmail.com > > This email sent to devarshi.bluec...@gmail.com -- Thanks, Devarshi ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Swift - Basic query regarding managedObjectContext method invocation from app delegate
> On 2014 Oct 14, at 05:42, Devarshi Kulshreshtha > wrote: > > I am trying to implement reset functionality in core data based sample app. > > I think that there are two ways to implement reset functionality: > > Approach 1: Delete sqlite file and then re-insert data As you’ve seen, this is tricky to do without relying on some Apple-impleentation-dependent behaviors. > Approach 2: Retrieve all data in managedObjectContext, delete > retrieved data and then re-insert data Performance may be unacceptable, and people will disrespect your code :) * * * How about a third approach: perform a managed object context reset(), followed by a save(). Does that work? Finally, if you’re in the modern world of Yosemite or iOS8, maybe some of the new direct database access methods will do what you want. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Swift - Basic query regarding managedObjectContext method invocation from app delegate
I am trying to implement reset functionality in core data based sample app. I think that there are two ways to implement reset functionality: Approach 1: Delete sqlite file and then re-insert data Approach 2: Retrieve all data in managedObjectContext, delete retrieved data and then re-insert data I tried 'Approach 1' first, here is the code snippet: @IBAction func resetData(sender: AnyObject) { let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate // delete old db if it exists var url = appDelegate.applicationDocumentsDirectory.URLByAppendingPathComponent("MyApp.sqlite") let defaultFileManager = NSFileManager.defaultManager() if defaultFileManager.fileExistsAtPath(url.path!) { defaultFileManager.removeItemAtURL(url, error: nil) } let managedObjectContext = appDelegate.managedObjectContext! var menuCategory : MenuCategories = NSEntityDescription.insertNewObjectForEntityForName("MenuCategories", inManagedObjectContext: managedObjectContext) as MenuCategories appDelegate.saveContext() } Then I added a break point in appDelegate's managedObjectContext lazy initialization method, here is the related code snippet: lazy var managedObjectContext: NSManagedObjectContext? = { let coordinator = self.persistentStoreCoordinator if coordinator == nil { return nil } var managedObjectContext = NSManagedObjectContext() managedObjectContext.persistentStoreCoordinator = coordinator return managedObjectContext }() First time when I performed reset action, the program counter (PC) stopped on the added break point, but next time when I performed reset action then the PC did not stop on the break point and app crashed for obvious reasons: Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x78f54ff0 {NSUnderlyingError=0x78f69250 "The operation couldn’t be completed. No such file or directory" Now my question is - Why second time managedObjectContext initialization method was not invoked? I know that I need to go back and learn Swift basics - the hard way, perhaps there is some obvious reasons which I am missing, please suggest. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com