<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTSourceCodeContext",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTSourceCodeContext"
  },
  "title" : "XCTSourceCodeContext"
}
-->

# XCTSourceCodeContext

An object that contains call stack and source code location details to provide context for a point of execution in a test.

```
class XCTSourceCodeContext
```

## Topics

### Initializers

[`init(callStack: [XCTSourceCodeFrame], location: XCTSourceCodeLocation?)`](/documentation/XCTest/XCTSourceCodeContext/init(callStack:location:))

Initializes a new instance with a provided call stack and source code location.

[`convenience init(callStackAddresses: [NSNumber], location: XCTSourceCodeLocation?)`](/documentation/XCTest/XCTSourceCodeContext/init(callStackAddresses:location:))

Initializes a new instance with an array of call stack addresses and a source code location.

[`convenience init(location: XCTSourceCodeLocation?)`](/documentation/XCTest/XCTSourceCodeContext/init(location:))

Initializes a new instance with a call stack from the executing thread and a provided source code location.

[`convenience init()`](/documentation/XCTest/XCTSourceCodeContext/init())

Initializes a new instance with a call stack from the executing thread and no location.

### Context Information

[`var callStack: [XCTSourceCodeFrame]`](/documentation/XCTest/XCTSourceCodeContext/callStack)

An array of source code frames that describes the call stack when a test issue occurs.

[`var location: XCTSourceCodeLocation?`](/documentation/XCTest/XCTSourceCodeContext/location)

A representation of a location in source code where a test issue occurred.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`Hashable`](/documentation/Swift/Hashable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)