Skip to content

Commit a68a681

Browse files
grynspaniamleeg
andauthored
Enhance documentation for URL attachments. (#1262)
Enhance documentation for [`Attachment.init(contentsOf:named:sourceLocation:)`](https://developer.apple.com/documentation/testing/attachment/init(contentsof:named:sourcelocation:)). In particular, provide info on what kind of URLs can be passed in, what the initializer awaits on, and how to use this (since there's intentionally no equivalent `record()` overload.) Resolves #1255. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated. --------- Co-authored-by: Graham Lee <[email protected]>
1 parent 893b4e8 commit a68a681

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Sources/Overlays/_Testing_Foundation/Attachments/Attachment+URL.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ extension Attachment where AttachableValue == _AttachableURLWrapper {
3636
///
3737
/// - Throws: Any error that occurs attempting to read from `url`.
3838
///
39+
/// Use this initializer to create an instance of ``Attachment`` that
40+
/// represents a local file or directory:
41+
///
42+
/// ```swift
43+
/// let url = try await FoodTruck.saveMenu(as: .pdf)
44+
/// let attachment = try await Attachment(contentsOf: url)
45+
/// Attachment.record(attachment)
46+
/// ```
47+
///
48+
/// When you call this initializer and pass it the URL of a file, it reads or
49+
/// maps the contents of that file into memory. When you call this initializer
50+
/// and pass it the URL of a directory, it creates a temporary zip file of the
51+
/// directory before reading or mapping it into memory. These operations may
52+
/// take some time, so this initializer suspends the calling task until they
53+
/// are complete.
54+
///
55+
/// - Important: This initializer supports creating attachments from file URLs
56+
/// only. If you pass it a URL other than a file URL, such as an HTTPS URL,
57+
/// the testing library throws an error.
58+
///
3959
/// @Metadata {
4060
/// @Available(Swift, introduced: 6.2)
4161
/// @Available(Xcode, introduced: 26.0)

0 commit comments

Comments
 (0)