<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTAttachment/lifetime-swift.property",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTAttachment(py)lifetime"
  },
  "title" : "lifetime"
}
-->

# lifetime

Indicates whether the attachment is kept or discarded when its associated test passes.

```
var lifetime: XCTAttachment.Lifetime { get set }
```

## Discussion

Defaults to [`XCTAttachment.Lifetime.deleteOnSuccess`](/documentation/XCTest/XCTAttachment/Lifetime-swift.enum/deleteOnSuccess), indicating that the attachment should be discarded when its test passes successfully, to save on storage space. Set this property to [`XCTAttachment.Lifetime.keepAlways`](/documentation/XCTest/XCTAttachment/Lifetime-swift.enum/keepAlways) to persist an attachment even when its test passes.

---

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)