From 67bb9340c77c9b13624b44d3a6f559229e4f5b72 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 5 Jul 2019 19:07:25 +0900 Subject: [PATCH] provide way to check if an object has updated properties --- Sources/BaseDataTransaction.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sources/BaseDataTransaction.swift b/Sources/BaseDataTransaction.swift index b61bd50..64c1790 100644 --- a/Sources/BaseDataTransaction.swift +++ b/Sources/BaseDataTransaction.swift @@ -213,6 +213,25 @@ public /*abstract*/ class BaseDataTransaction { // MARK: Inspecting Pending Objects + + /** + Returns `true` if the object has any property values changed. This method should not be called after the `commit()` method was called. + + - parameter entity: the `DynamicObject` instance + - returns: `true` if the object has any property values changed. + */ + public func objectHasPersistentChangedValues(_ entity: D) -> Bool { + + CoreStore.assert( + self.isRunningInAllowedQueue(), + "Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue." + ) + CoreStore.assert( + !self.isCommitted, + "Attempted to access inserted objects from an already committed \(cs_typeName(self))." + ) + return entity.cs_toRaw().hasPersistentChangedValues + } /** Returns all pending `DynamicObject`s of the specified type that were inserted to the transaction. This method should not be called after the `commit()` method was called.