Skip to content

Instantly share code, notes, and snippets.

@ncreated
Created September 3, 2017 23:00
Show Gist options
  • Save ncreated/4ad64e0a24415ee8ba10c25d7e6a9f87 to your computer and use it in GitHub Desktop.
Save ncreated/4ad64e0a24415ee8ba10c25d7e6a9f87 to your computer and use it in GitHub Desktop.
Medium blogpost snippet
func test_givenUnlockedSecureStorage_whenSavingValue_itCanBeLaterRead() {
let storage = SecureStorage<String>()
let unlockExpectation = self.expectation(description: "secure storage is unlocked")
let saveExpectation = self.expectation(description: "value is saved")
let readExpectation = self.expectation(description: "value is read")
storage.unlock { (unlocked) in
XCTAssertTrue(unlocked)
unlockExpectation.fulfill()
}
wait(for: [unlockExpectation], timeout: 1)
storage.save("secret") {
saveExpectation.fulfill()
}
wait(for: [saveExpectation], timeout: 1)
storage.read { value in
XCTAssertEqual(value, "secret")
readExpectation.fulfill()
}
wait(for: [readExpectation], timeout: 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment