Browse Questions
  • A Singleton ensures only one instance of a class exists globally.
  • Secure Message is a stateless asymmetric primitive that encrypts or signs a single payload using your private key and the peer's public key, making it a natural fit for request/response APIs.
  • UITableView reuses cell objects as they scroll off screen rather than creating new ones, keeping memory usage constant regardless of how many rows exist.
  • XCTAssert functions are how you verify expected behaviour in tests.

Answer: XCTAssert functions are how you verify expected behaviour in tests. Each checks a different condition and fails the test with a message if the condition isn't met.

Code Example:

// Equality
XCTAssertEqual(result, 42)
XCTAssertNotEqual(result, 0)

// Boolean
XCTAssertTrue(isValid)
XCTAssertFalse(isLoading)

// Nil checks
XCTAssertNil(errorMessage)
XCTAssertNotNil(user)

// Comparable
XCTAssertGreaterThan(score, 0)
XCTAssertLessThanOrEqual(count, 100)

// Throws
XCTAssertThrowsError(try service.fetch()) { error in
    XCTAssertEqual(error as? APIError, .unauthorized)
}
XCTAssertNoThrow(try validator.validate(input))

// Always fail (e.g. in a switch default)
XCTFail("Unexpected state reached")