Custom Manual Migration Policy
Intermediate Training Core Data
What happens when your Core Data models version are no longer compatible with each other? Well, you'll have to resolve this inconsistencies through Custom Migration Policies. This is quite difficult and can be resolved in several ways. In today's video, we'll look at using a Mapping Model as well as NSEntityMigrationPolicy. I hope these examples will be helpful in correctly guiding you through this rough concept.

Comments (30)
Te-Jen Wu
5 years ago
Hi Brian, Thanks for your teaching course, which is of great benefits to us. I have a question: when should we use NSIncrementalStore and how to use it appropriately ?
StanyMiles
5 years ago
Thank you Brian! This course is helped me a lot!
Alpensol
5 years ago
Hey Brian, thanks for the course. I am almost done, but keep getting this error during custom migration and I have no clue what is wrong. Please help ... returned error Error Domain=NSCocoaErrorDomain Code=134110 "(null)" UserInfo={NSUnderlyingException=Couldn't create mapping policy for class named (LBTA-CD.CustomMigrationPolicy)} with userInfo dictionary { NSUnderlyingException = "Couldn't create mapping policy for class named (LBTA-CD.CustomMigrationPolicy)"; }
Brian Voong
5 years ago
macgallagher
5 years ago
Alpensol, I had the same error - it turns out the problem is the just project name. For some reason, XCode seems to dislike the dash "-" in the project name. If you rename your project to something like LBTACoreData, everything should work fine!
daver235
5 years ago
Great course Brian. Nice job!
Yunio
5 years ago
hey man great course really like that you are the only one on the internet teaching code in ui. I believe you create the best student really appreciate you man. I just really want you to have all the beginners into swift to learn with you that way is a better understanding with that being said have you ever tried making a video on convincing how ui code is better than storyboards and showing them in code this is why is better and if someone drags a tableView in story board how to show them how to do the same in code like that they can also see other videos and fully understand how to do it in code cus every job you need to be able to make ui in code
Brian Voong
5 years ago
chuckie
5 years ago
Really great course! Thank you very much Brian! Videos like these are so motivating keeping on doing ios-development. Hope you're not falling off too much into Kotlin/Android Development ;)
Brian Voong
5 years ago
Share App
5 years ago
Great course! Thanks! I’m curious about how this would work to use Core Data and also store on Firebase or some other database — in case there’s anything in particular needed to be done to work with both Core Data and Firebase.
Kilian Hiestermann
5 years ago
Awesome! Had a lot of fun!
marcelreijerink
5 years ago
Hello I started the downloaded project with no adjustments after create employee and save: get error employee setvalue for undefined key the entity employee is not key value coding compliant for the key name
Brian Voong
5 years ago
jacquesj
5 years ago
hello Brian, hope you are well. I am having the same issue as marcelreijerink. The app is crashing when trying to save new employees.
ksnnacar
5 years ago
Hey Brian. I just finished the intermediate training core data project after the kindle basic course and quite enjoyed that one as well. Learned a ton. Will you add new episodes to this project? It feels like it will continue on the last video? Thanks again. Will continue with instagram next week and podcasts next month. Cheers!
Ashim Dahal
5 years ago
​Hi Brian, I thought there is still some content missing from this tutorial. We implemented many features on table view which was absent on company autoupdateController. Every time I refresh the company autoupdate controller it's adding all the companies again in the table view. I thought it would add any new company that changes in the JSON file but it's not doing that for me. Your input is really appreciated.
Brian Voong
5 years ago
JesperBjerggaard
5 years ago
Thanks Brian, for this course. I hope you will consider an extra episode with the mentioned feature above. You are the best the way you teach and explain is fantastic.
Dekatria
4 years ago
Hello Brian, Are you still thinking about adding a video to this course that will help us export from Core Data to JSON. Thank you
magic
5 years ago
Can’t express my feelings!! Thank you very much for all of this great teachings ❤️❤️❤️
jpatrickmc
5 years ago
Awesome training course Brian! Your instruction style is very effective. I look forward to future iOS and Swift courses you put together.
Tube
5 years ago
YAGC = Yet Another Great Course. I request a short 15' Bonus lesson showing us how to persist a video as a Core Data blob. Maybe we can figure this out for ourselves, but I always like to begin with your procedure, so I know it will be professional.
sean
5 years ago
Really love your course man ! Thank u so much for all the hard work.
pushtoplay
5 years ago
Brian, this course was a perfect match for me! I am an experienced LAMP developer and will be writing an iOS app. The pace and depth was just right. I feel you provided all the tools I need to get started. Keep up the great work.
dclawson
5 years ago
Another one done! I've been trying to learn Swift for a long time now, and this format has worked for me FAR greater than anything else. Thanks, and looking forward to the next courses.
Rupali Ghate
5 years ago
Finished this one. Had a lot of in-depth learning on CoreData. Another great course, Thanks! Hoping to complete Instagram and Podcasts courses as well.
shubhamsaurav
5 years ago
Brain, thank you so much for creating this course. I learned a lot from you in this course. I have been learning iOS development for four months now and the money spent on this course was the greatest investment I ever made. I am also enrolled in Instagram Course and I will start that course from the next week. Would like to buy your upcoming courses on this website? Thanks once again, Shubham Saurav
William Muñoz Rodas
5 years ago
Hello Brian, thank you so much for this course. I have the following doubt: suppose a user didn't update from version 1.0 to 1.1, and you as developer release the version 2.0. Is not clear for me if once the user hit update in Apple Store, the process update first to version 1.1 and the to 2.0 or starts the update directly to version 2.0. I tried to replicate the scenario installing the application of the video 30 and then update Core Data running the application from video 32, the application crashed because the intermediate update from video 31. Could you help us with this scenario?
Brian Voong
5 years ago
William Muñoz Rodas
5 years ago
Hey Brian, Thank you for answering this question. Yes, I replicated a scenario to see what happen when the application goes from version 1.0 to 4.0, passing by 2.0 and 3.0 versions. A good designed application must take in account all the versions to reach the final version. And what to do when something goes wrong, I mean, to save the last version and inform the user about it. What I learn from this course is that the best approach with Core Data is to design your Entities and Relationships since the beginning, and never perform drastic changes.
ravikanth.marri@gmail.com
4 years ago
Thanks Brian , Your teaching style is excellent , I learned a lot.
adria1
4 years ago
Brian, I loved your course, but I have a problem: I want in an entity called Room, to have an array of the entity Person (basically I want an attribute in Room with a custom type Person), but when doing room.persons = currentRoomPersons the application is blocked and a SIGARBT error occurs, the current code it's something like this: Room+CoreDataClass.swift: import Foundation import CoreData @objc(Room) public class Room: NSManagedObject {} Room+CoreDataProperties.swift import Foundation import CoreData extension Room { @nonobjc public class func fetchRequest() -> NSFetchRequest<Room> { return NSFetchRequest<Room>(entityName: "Room") } @NSManaged public var persons: [Person]? // Array of entity "Person" in the room. } What am I doing wrong? Great videos!
Brian Voong
4 years ago
adria1
4 years ago
Hey Brian, Thanks for responding so fast, this is what it says: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Room setPersons:]: unrecognized selector sent to instance 0x600001d1eee0'
adria1
4 years ago
Code uploaded to Github, if you want to look at the whole code or even try it on your own: https://goo.gl/kL5jxV
xuhua
4 years ago
老师我遇到一个问题,但不是您课程里的,不知道能不能问。 就是,我现在所有东西都是程序写的,没有用storyborad,我现在想在一个uiview上有一个segment来选择显示两个uitableview,但是我发现不会如何将以ui tableview添加到这个uiview上面去,我网上查了半天都是用storyboard方法的,所以只能来麻烦您了。您给个大概思路就行,非常感谢。
xuhua
4 years ago
https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/%E7%B0%A1%E6%98%93%E8%AA%AA%E6%98%8Excode%E4%B8%ADobject-library%E7%9A%84segmented-control-34fcf11f0b53 就是要实现这个效果,但下面是uitableview,并且只用代码。
Brian Voong
4 years ago
xuhua
4 years ago
谢谢老师回复!我刚刚看了您的一个blog,是类似的功能,可以显示自己但tableview没问题,点cell不能push到其他view了。 老师您有微信吗?我可以付费让您帮我写这段代码吗?我实在是找不到解决办法了。。。 我的微信是 xuhuafilm 谢谢您。
Brian Voong
4 years ago
xuhua
4 years ago
我的上帝,您太好了!我都热泪盈眶了!刚刚看到这个留言。我一定再买您的课,并且期待您能来中国!
Cinquain
4 years ago
Finally finished this last tutorial. Core Data done!
cicihuang
4 years ago
老师你好,我看见从json download image你没有implement于是自己写了一个。 guard let imageurl = URL(string: jsonCompany.photoUrl) else { return } print (imageurl) URLSession.shared.dataTask(with: imageurl) { (data, resp, err) in if let err = err { print ("Failed to download image", err) return } guard let data = data else {return} print(data) company.imageData = data } 但是当我refresh的时候,table view并没有更新公司的照片,这是为什么呢?谢谢
Brian Voong
4 years ago
Sa Shankar
4 years ago
Hi Brain I've done a project with core data it has 13 entities embedded with all type of relations. I'm trying to sync with CloudKit by using 'NSPersistenceCloudKitContainer' iOS13. the schema is not copying to the iCloud container. Can you help me out. Thanks S Shanakar
Cinquain
4 years ago
Excellent course. Will definitely rewatch one last time
GeminixClown
3 years ago
Awesome course, i really hope you will consider to adding one more bonus video to sync this app to CloudKit.
Nelson Pedrozo
3 years ago
Hello Brian, my sincere congratulations on a great course. Your learn-by-doing teaching style is superb, as is your attention to detail. Definitely top-notch. I have one question, though, not at all related to programming: I could not find any of the "links down below" for things such as a more in-depth explanation of tuples (lesson 18), or DispatchQueues, or whatnot. Are the links on another, perhaps earlier, platform where you placed your courses? -- Nelson (Cal Berkeley '93)
Manish Prakharan
2 years ago
Hello Brian, A quick question when you have changed the value expression with "FUNCTION($entityPolicy, "transformingMethodName" , $source.numEmployees)" this is my own value expression for numEmployees which I have put in my ComanyToCompany mappings and now I have build a transformation file which extends "NSEntityMigrationPolicy". And now I have implemented a method transformingMethodName wwhich I have written as ``` @objc func transformingMethodName() -> Int { return 900 } ``` So I am getting a crash. And when i write a function with Void returns It won’t gives me crash ``` @objc func transformingMethodName() { } ``` So now the question is How do I change the data for my attribute in this class. i am not able to write the methods here. And when I do it It gives me a crash. I am not understanding the way how do you start began writing methods here and change the attributes value respectively.
HELP & SUPPORT