Skip to content

Commit ebb1cc3

Browse files
authored
Merge pull request #2241 from compnerd/flexion
TestFoundation: ensure that `NSValue` is preserved
2 parents 042b2ba + a026128 commit ebb1cc3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

TestFoundation/TestNSKeyedArchiver.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,16 @@ class TestNSKeyedArchiver : XCTestCase {
289289
guard let value = unarchiver.decodeObject(of: NSValue.self, forKey: "root") else {
290290
return false
291291
}
292-
var expectedCharPtr: UnsafeMutablePointer<CChar>? = nil
293-
value.getValue(&expectedCharPtr)
294-
295-
let s1 = String(cString: charPtr)
296-
let s2 = String(cString: expectedCharPtr!)
297292

298-
return s1 == s2
293+
return withExtendedLifetime(value) { value in
294+
var expectedCharPtr: UnsafeMutablePointer<CChar>? = nil
295+
value.getValue(&expectedCharPtr)
296+
297+
let s1 = String(cString: charPtr)
298+
let s2 = String(cString: expectedCharPtr!)
299+
300+
return s1 == s2
301+
}
299302
})
300303
}
301304

0 commit comments

Comments
 (0)