Skip to content

Commit 52ec53d

Browse files
committed
Customize documentation for protocol conformances of Encodable and NSSecureCoding
1 parent 4ebf0f7 commit 52ec53d

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Sources/Overlays/_Testing_Foundation/Attachments/Encodable+Test.Attachable.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,38 @@ private import Foundation
1717
// protocol for types that already support Codable.
1818
@_spi(Experimental)
1919
extension Encodable where Self: Test.Attachable {
20+
/// Encode this value into a buffer using either [`PropertyListEncoder`](https://developer.apple.com/documentation/foundation/propertylistencoder)
21+
/// or [`JSONEncoder`](https://developer.apple.com/documentation/foundation/jsonencoder),
22+
/// then call a function and pass that buffer to it.
23+
///
24+
/// - Parameters:
25+
/// - attachment: The attachment that is requesting a buffer (that is, the
26+
/// attachment containing this instance.)
27+
/// - body: A function to call. A temporary buffer containing a data
28+
/// representation of this instance is passed to it.
29+
///
30+
/// - Returns: Whatever is returned by `body`.
31+
///
32+
/// - Throws: Whatever is thrown by `body`, or any error that prevented the
33+
/// creation of the buffer.
34+
///
35+
/// The testing library uses this function when writing an attachment to a
36+
/// test report or to a file on disk. The encoding used depends on the path
37+
/// extension specified by the value of `attachment`'s ``Testing/Test/Attachment/preferredName``
38+
/// property:
39+
///
40+
/// | Extension | Encoding Used | Encoder Used |
41+
/// |-|-|-|
42+
/// | `".xml"` | XML property list | [`PropertyListEncoder`](https://developer.apple.com/documentation/foundation/propertylistencoder) |
43+
/// | `".plist"` | Binary property list | [`PropertyListEncoder`](https://developer.apple.com/documentation/foundation/propertylistencoder) |
44+
/// | None, `".json"` | JSON | [`JSONEncoder`](https://developer.apple.com/documentation/foundation/jsonencoder) |
45+
///
46+
/// OpenStep-style property lists are not supported.
47+
///
48+
/// - Note: On Apple platforms, if the attachment's preferred name includes
49+
/// some other path extension, that path extension must represent a type
50+
/// that conforms to [`UTType.propertyList`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/propertylist)
51+
/// or to [`UTType.json`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/json).
2052
public func withUnsafeBufferPointer<R>(for attachment: borrowing Test.Attachment, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
2153
let format = try EncodingFormat(for: attachment)
2254

Sources/Overlays/_Testing_Foundation/Attachments/NSSecureCoding+Test.Attachable.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,35 @@ public import Foundation
1717
// NSKeyedArchiver for encoding.
1818
@_spi(Experimental)
1919
extension NSSecureCoding where Self: Test.Attachable {
20+
/// Encode this object using [`NSKeyedArchiver`](https://developer.apple.com/documentation/foundation/nskeyedarchiver)
21+
/// into a buffer, then call a function and pass that buffer to it.
22+
///
23+
/// - Parameters:
24+
/// - attachment: The attachment that is requesting a buffer (that is, the
25+
/// attachment containing this instance.)
26+
/// - body: A function to call. A temporary buffer containing a data
27+
/// representation of this instance is passed to it.
28+
///
29+
/// - Returns: Whatever is returned by `body`.
30+
///
31+
/// - Throws: Whatever is thrown by `body`, or any error that prevented the
32+
/// creation of the buffer.
33+
///
34+
/// The testing library uses this function when writing an attachment to a
35+
/// test report or to a file on disk. The encoding used depends on the path
36+
/// extension specified by the value of `attachment`'s ``Testing/Test/Attachment/preferredName``
37+
/// property:
38+
///
39+
/// | Extension | Encoding Used | Encoder Used |
40+
/// |-|-|-|
41+
/// | `".xml"` | XML property list | [`NSKeyedArchiver`](https://developer.apple.com/documentation/foundation/nskeyedarchiver) |
42+
/// | None, `".plist"` | Binary property list | [`NSKeyedArchiver`](https://developer.apple.com/documentation/foundation/nskeyedarchiver) |
43+
///
44+
/// OpenStep-style property lists are not supported.
45+
///
46+
/// - Note: On Apple platforms, if the attachment's preferred name includes
47+
/// some other path extension, that path extension must represent a type
48+
/// that conforms to [`UTType.propertyList`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/propertylist).
2049
public func withUnsafeBufferPointer<R>(for attachment: borrowing Test.Attachment, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
2150
let format = try EncodingFormat(for: attachment)
2251

0 commit comments

Comments
 (0)