This is a question similar to one that has been asked before by bjmiller22:
have you tried to make a computed property on the Device NSMO subclass for purchasedOnSameDate : [Device] just as a safer way to get the valueForKey("purchasedOnSameDate") as? [Device] array? I thought it would be great to have it just like any other property on the class, but it crashes every time it is accessed. Even adding it inside if let binding still crashes, and no useful output in the console is given
According to your reply, I understand that this can be achieved if I name this property different from the fetched property’s name. But I do not understand why I could not access the fetched property directly, as you said there is already one on the object? Such as:
I thought this would return an array of values, but xcode complains that there is no such property (I have tried to update the subclass). My guess is since this is a computational property, it is created on the fly during run time?
Thank you so much! The course is really helpful for me to understand core data!
When you add the try/catch to catch the validation error, in the catch you assume the error is a validation error and put up a message without further testing this. I think that is a bad programming habit, you should always be sure what you’re in a catch for and provide program flow for that.
Also, you do show the concept of (field/value) validation but not constraints (such as uniqueness) even though the description of the video states ‘constraints’.
Could you please in addition provide a working example on how to change an attributes type by applying a custom migration policy? I have an annual subscription at raywenderlich.com and also bought the book “Core Data by Tutorials”. However, I could not find a solution to my problem yet.
In my particular case I have an entity called Location with the common attributes latitude and longitude. In version 1 of my data model both attributes are of type String. In version 2 I have changed the type to Double.
Next I have created a mapping model including the entity mapping LocationToLocation. In the respective value expressions I’ve added FUNCTION($entityPolicy, "stringToDoubleWithString:" , $source.latitude). As custom policy I have added MyApp.LocationToLocationMigrationPolicy1to2 to the mapping model.
The corresponding custom migration policy file looks like this: