Skip to content

Add a preferredName(for:basedOn:) member to Attachable to allow customizing filenames. #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Dec 12, 2024

This PR introduces a new optional member of Attachable, preferredName(for:basedOn:), that we use when writing the corresponding attachment to disk/test reports/etc. in order to allow attachable types to customize the name independently of what the user specifies.

For example:

let a = Attachment(x)
let b = Attachment(y, named: "hello")

In both the attachments created above, the file name is incompletely specified. a has a default name, and both a and b have no path extension (which is important for the OS to correctly recognize the produced file's type.) By adding this new function to Attachable, we give x and y the opportunity to say "this is JPEG data" or "this is plain text" (and so forth.)

The new function is implemented by _AttachableImageContainer. I've also created _AttachableURLContainer to represent files mapped from disk for attachment (instead of directly passing them around as Data.)

Third-party conforming types will generally want to use Foundation's NSString or URL API to append path extensions (etc.)

Note

Attachments remain experimental.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

…ustomizing filenames.

This PR introduces a new optional member of `Attachable`, `preferredName(for:basedOn:)`,
that we use when writing the corresponding attachment to disk/test reports/etc. in order
to allow attachable types to customize the name independently of what the user specifies.

For example:

```swift
let a = Attachment(x)
let b = Attachment(y, named: "hello")
```

In both the attachments created above, the file name is incompletely specified. `a` has a
default name, and both `a` and `b` have no path extension (which is important for the OS
to correctly recognize the produced file's type.) By adding this new function to
`Attachable`, we give `x` and `y` the opportunity to say "this is JPEG data" or "this is
plain text" (and so forth.)

The new function is implemented by `_AttachableImageContainer`. I've also created
`_AttachableURLContainer` to represent files mapped from disk for attachment (instead of
directly passing them around as `Data`.)

Third-party conforming types will generally want to use Foundation's `NSString` or `URL`
API to append path extensions (etc.)
@grynspan grynspan added enhancement New feature or request public-api Affects public API attachments/activities 🖇️ Work related to attachments and/or activities labels Dec 12, 2024
@grynspan grynspan self-assigned this Dec 12, 2024
@grynspan grynspan added this to the Swift 6.x milestone Dec 12, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit 993c7cb into main Dec 12, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/make-preferred-name-method branch December 12, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attachments/activities 🖇️ Work related to attachments and/or activities enhancement New feature or request public-api Affects public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants