How to Perform a Lightweight Core Data Migration

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

How to Perform a Lightweight Core Data Migration

Postby rwenderlich » Thu Feb 14, 2013 11:00 am

This is the official thread to discuss the following blog post: How to Perform a Lightweight Core Data Migration
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2145
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 332 times

Re: How to Perform a Lightweight Core Data Migration

Postby alnp1987 » Thu Feb 14, 2013 6:15 pm

Thanks for the great tutorial Scott. I have one question. Can you explain why you decided to pass in an NSManagedObject to the DetailViewController instead of an NSManagedObjectContext when creating a new Thought? I understand that passing the managed object requires to implement a rollback functionality as you mentioned if the users cancels, but wouldn't be more efficient to have DetailViewController create the managed object and save it only when the user taps a save button? If not, how would one go about implementing the rollback functionality?
alnp1987
n00b
 
Posts: 3
Joined: Thu Nov 03, 2011 1:13 am
Has thanked: 0 time
Been thanked: 1 time

Re: How to Perform a Lightweight Core Data Migration

Postby scotteg » Fri Feb 15, 2013 2:35 pm

@alnp1987 Thanks, glad you liked it! You could delay creating a new managed object until when Save is tapped. This would involve caching the data, e.g., in a dictionary in the create/edit view controller, and then accessing that dictionary in a delegate in a method such as someDetailViewControllerDidFinish, where you would proceed with creating a new managed object and assigning the values. To implement rollback, you would first create and set an undo manager on your managed object context when you instantiate it, and then to rollback, just call rollback on your managed object context in your delegate in a method such as someDetailViewControllerDidCancel. These are great questions, which do go beyond the scope of this tutorial, though. Hopefully my brief comments help to steer you in the right direction. Good luck!
User avatar
scotteg
Team Member
Hacker
 
Posts: 20
Joined: Sun May 01, 2011 11:15 pm
Location: Greater St. Louis area
Has thanked: 4 times
Been thanked: 1 time

Re: How to Perform a Lightweight Core Data Migration

Postby johnheb » Fri Feb 22, 2013 3:49 am

Great Tutorial especially the explanation.

I have a business app and I am using iCloud which is working fine. However, lightweight migration and iCloud don't seem to want to play together. Your thoughts?

Thanks

John
johnheb
Baby Hacker
 
Posts: 8
Joined: Mon Oct 08, 2012 12:07 pm
Has thanked: 1 time
Been thanked: 1 time

Re: How to Perform a Lightweight Core Data Migration

Postby scotteg » Fri Mar 01, 2013 2:28 pm

@johnheb Thanks! I haven't done anything with iCloud in a while. What I have been meaning to do though is check out StackMob's service, which is integrated with Core Data. What sort of issues are you having with using Core Data and iCloud after doing a migration? Also, have you filed a radar with Apple?
User avatar
scotteg
Team Member
Hacker
 
Posts: 20
Joined: Sun May 01, 2011 11:15 pm
Location: Greater St. Louis area
Has thanked: 4 times
Been thanked: 1 time

Postby w4t3rw4lk3r » Thu Jun 20, 2013 4:12 pm

Hi Scott, I tried this but I get this error every time i try to build at the end of the tutorial.
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_mainAppDelegate", referenced from:
objc-class-ref in main.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

any help?
Thanks.
w4t3rw4lk3r
Baby Hacker
 
Posts: 8
Joined: Tue Aug 14, 2012 9:54 am
Has thanked: 1 time
Been thanked: 0 time

Re: How to Perform a Lightweight Core Data Migration

Postby scotteg » Sat Jul 20, 2013 12:05 pm

Hi, I'm not really sure what could exactly be causing your issue. Have you tried starting over with a new project, just to be sure you got all the steps exactly and in the order specified? I know it's happened to me many times that I've missed just one little thing following along with a tutorial, and I get a big 'ole crasher. Let me know if you go through the tutorial with a new project and still encounter an issue. Thanks!
User avatar
scotteg
Team Member
Hacker
 
Posts: 20
Joined: Sun May 01, 2011 11:15 pm
Location: Greater St. Louis area
Has thanked: 4 times
Been thanked: 1 time

Re: How to Perform a Lightweight Core Data Migration

Postby sjurygg » Mon Aug 19, 2013 12:42 pm

Thanks for the great tutorial. What if the app in the example would have had a prefilled sqlite with banks. Users are later then adding tags and other info. Then if the shipped bank data was updated with new banks after first release of the app. Is then lightweight migration recommended or even possible?
sjurygg
n00b
 
Posts: 3
Joined: Mon Aug 19, 2013 11:44 am
Has thanked: 1 time
Been thanked: 0 time

Re: How to Perform a Lightweight Core Data Migration

Postby rcasey » Mon Aug 19, 2013 4:12 pm

Lightweight migrations are for changes in the data model.

If you wanted to include new banks in a new release of the app, you would need to provide a mechanism for loading that new data independently of any data model migration that might also take place.
rcasey
Team Member
Forum Subject Matter Expert
 
Posts: 1173
Joined: Fri Jul 01, 2011 6:50 pm
Has thanked: 2 times
Been thanked: 254 times

Re: How to Perform a Lightweight Core Data Migration

Postby jens095 » Tue Sep 17, 2013 1:51 pm

Hello
My app contains a static coreData instance, that is, it is initialized together with the app and the user cannot add/change anything to it.
In a future version, how do I get the new coreData contents to the app, assuming the model is unchanged.
I can scratch the entire old contents and add the new one, but how is that done in an easy way ?
As understand it, this is not a migration as defined in your tutorial.
kind regards

Jens Henriksen
jens095
n00b
 
Posts: 1
Joined: Tue Sep 17, 2013 1:42 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests