@@ -91,6 +91,47 @@ class Threading: XCTestCase {
91
91
// :code-block-end:
92
92
}
93
93
94
+ func testThaw( ) {
95
+ let realm = try ! Realm ( )
96
+
97
+ try ! realm. write {
98
+ realm. add ( Task ( ) )
99
+ }
100
+
101
+ let frozenRealm = realm. freeze ( )
102
+
103
+ // :code-block-start: thaw
104
+ // Read from a frozen realm
105
+ let frozenTasks = frozenRealm. objects ( Task . self)
106
+
107
+ // The collection that we pull from the frozen realm is also frozen
108
+ assert ( frozenTasks. isFrozen)
109
+
110
+ // Get an individual task from the collection
111
+ let frozenTask = frozenTasks. first!
112
+
113
+ // To modify the task, you must first thaw it
114
+ // You can also thaw collections and realms
115
+ let thawedTask = frozenTask. thaw ( )
116
+
117
+ // Check to make sure this task is valid. An object is
118
+ // invalidated when it is deleted from its managing realm,
119
+ // or when its managing realm has invalidate() called on it.
120
+ assert ( thawedTask? . isInvalidated == false )
121
+
122
+ // Thawing the task also thaws the frozen realm it references
123
+ assert ( thawedTask!. realm!. isFrozen == false )
124
+
125
+ // Let's make the code easier to follow by naming the thawed realm
126
+ let thawedRealm = thawedTask!. realm!
127
+
128
+ // Now, you can modify the task
129
+ try ! thawedRealm. write {
130
+ thawedTask!. status = " Done "
131
+ }
132
+ // :code-block-end:
133
+ }
134
+
94
135
func testPassAcrossThreads( ) {
95
136
let expectation = XCTestExpectation ( description: " it completes " )
96
137
// :code-block-start: pass-across-threads
0 commit comments