Comments (5)
@mbrucedogs the merge policy on the MOC shouldn't need to change.
There are two things that I've noticed being issues with creating a unique constraints that I would double check:
- Unique constraints must be of type String (This is very poorly documented by Apple and can easily trip you up)
- After editing the comma separated value section in the XCDataModel editor be sure to save the file. I've seen these changes disappear when moving to another source file.
#92 is up for PR now and will add an example.
from coredatastack.
Robert,
Thanks for your previous post here, it seems I have gotten the unique constraints to work. However, is there some trick to getting Unique Constraints to work on a one-many relationship? I know this is more of a Advanced Core Data question and not really a CoreDataStack, but you obviously know a ton about Core Data and I was hoping you have run into this before.
If you don't have time or want to answer can you point me to a source that might could help me out? If you want to help, great read below, otherwise sorry for bothering you or wasting your time, you have been a great help already with what you have written.
Problem:
I can't seem to get things to update in a Set even though the managed objects in the Set have a Unique Constraint.
To be clear, I am parsing JSON which contains a User object, with an array of Address objects. I have a User ManagedObject with a property called addresses that contains a Set
which is a 1 to many relationship from a User to a Address. When I parse the full JSON I am creating the User ManagedObject, and looping through the address's and creating Address ManagedObjects which get put into the User.addresses Set. Both my User and Address do have Unique Constraints.An example of the issue I am dealing with is the JSON in these Users can have several addresses like a home, work or shipping etc... All I want to do is be able to make sure that CoreData isn't creating new addresses with the same Id and update the existing address with changes, but also deleting Address that no long are in the Set
. I do have a constraint on the addresses with an Id, however the problem I am seeing is that new Address objects or Old ones get updated, however any Address objects that aren't returned don't get removed.1st JSON Response) get JSON with User having 3 addresses (address1,address2, address3). Parse into User Object with 3 addresses in the Set
Core Data Result) all of this gets created just fine, 1 User with 3 Address managed objects
2nd JSON Response) User updates, and you get new JSON with User having 2 Addresses (address1, address3). Parse into User Object with 2 addresses in the Set
Core Data Result) Now the addresses Set has 2, address1 and address3 are still in the system, but even though address2 wasn't included in the Set, it still remains in the database and connected to the user?
I would think the merge would overwrite the old Set
with 3 items with the new Set with 2 items? Am I hoping for too much in Core Data or do I need to go old school and pull the data ahead of time and do a manual diff-merge?The only solution I have found to be a winner is doing a batch delete of all address of the user Id to ensure the correct Core Data response occurs.
Any thoughts and if you have read to this point again I want to thank you for at least taking the time.
Matt
from coredatastack.
Hi @mbrucedogs from skimming over this I too would assume that a User would have only two addresses if you've set his addresses
property to an Set<Address>
containing only two objects.
That being said the iOS 9 feature of uniqueness does not delete "stale" data. So anything already persisted will still be present. My feelings currently is that this feature isn't quite ready for prime time.
In my projects I'm not using this yet and continue to do an Insert, Update, and Purge for each data type I'm syncing.
Good luck with your solution.
from coredatastack.
As an example if you run the sample project and remove a book from the BookTestData.swift
file you will still see that in the Fetched Results Controller
from coredatastack.
Your feelings are mine as well on Unique Constraints. It seems that Apple always puts out features like Unique Constraints to handle extremely basic examples without dealing more complex designs, like handling objects that have NO relationships, which at least in my applications rarely occur.
Thanks again for your response, I do appreciate hearing this from a developer outside of my work environment.
from coredatastack.
Related Issues (20)
- Can't run app in simulator with BNRCoreDataStack in Objective-C project, LaunchServicesError HOT 1
- Build issues with Xcode 8 beta 3 HOT 4
- Creating CoreDataStack without dispatching HOT 2
- When using Mogenerator, making a ManagedObject implement CoreDataModelable gives error HOT 6
- NSPersistentStoreCoordinator options. HOT 5
- (Swift 3) Make `performAndWaitOrThrow` `rethrows` and `@noescape` HOT 1
- Issue compiling project with BNRCoreDataStack using Xcode 8 - Swift 2.3 HOT 1
- Publish Pod version 2.0.0 HOT 1
- performAndWaitOrThrow not accessible HOT 5
- Linker issue HOT 2
- Linker issue HOT 5
- Entity name check should not fail because of module name HOT 5
- BNRCOredatastack 1.3.0 issue in xcode 8.2 unable to install on device
- Question: is `.findFirstInContext(...)` not available any more on iOS < 10? HOT 3
- Support programatically created object models HOT 2
- Carthage validation script fails for forks
- Use withoutActuallyEscaping for helpers on Swift 3.1 HOT 5
- How can i use CoreDataStack in an Objective-C project HOT 1
- Xcode 9 support HOT 1
- crash on update of app from app store HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coredatastack.