Avoid duplicte objects checking NSManagedObjectContext registered objects

I found, that in some cases, entities may be inserted duplicated. 

To illustrate this case : 

The API was returning "actions" done by "users". Each action entity has its own user entity, but a user may have many actions. 

If this is the first time my application make this request, I won't have any user saved to disk. So if the API returns some actions done by the same user, when my application calls updateOrInsertIntoManagedObjectContext:withDictionary: , it will fetch for each user to disk, and it will return nothing on every call so there is no users saved to disk.

I added an extra checkup, and look on every managed object context registered objects, so the entity may be already created in context. 

If an entity with the same class and primaryKey is found, it returns and perform an update instead an insert. 
 

Signed-off-by: Daniel Garcia <fillito@gmail.com>