From 88ab0b5e15a2577e29fa7e678f99702462bcc93b Mon Sep 17 00:00:00 2001 From: John Estropia Date: Mon, 28 Oct 2019 12:03:17 +0900 Subject: [PATCH] provide direct conversion from DynamicObject to ObjectSnapshot --- Sources/ObjectRepresentation.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/ObjectRepresentation.swift b/Sources/ObjectRepresentation.swift index 3eb2f64..863366c 100644 --- a/Sources/ObjectRepresentation.swift +++ b/Sources/ObjectRepresentation.swift @@ -75,6 +75,19 @@ extension CoreStoreObject: ObjectRepresentation {} extension DynamicObject where Self: ObjectRepresentation { + // MARK: Public + + /** + A thread-safe `struct` that is a full-copy of the object's properties + */ + public func asSnapshot() -> ObjectSnapshot? { + + return self.cs_toRaw() + .managedObjectContext + .flatMap({ ObjectSnapshot(objectID: self.cs_id(), context: $0) }) + } + + // MARK: ObjectRepresentation public func objectID() -> Self.ObjectID {