Skip to content

Allow initialization and addition of AcknowList #133

Merged
vtourraine merged 1 commit into
vtourraine:mainfrom
ChaosCoder:main
Apr 14, 2026
Merged

Allow initialization and addition of AcknowList #133
vtourraine merged 1 commit into
vtourraine:mainfrom
ChaosCoder:main

Conversation

@ChaosCoder

@ChaosCoder ChaosCoder commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

I am using Acknowlist with SwiftUI and generate the list from the package, which works great.

However, I need to add items to the list, that are not in the package (e.g. graphics licenses, etc.). But the defined + operator for two AcknowList is not public. Initializing of a AcknowList is also not possible from outside the package and the properties including the acknowledgements on an AcknowList are defined with let and therefor can not be mutated.

This PR fixes the first two things, so you can do stuff like:

let listFromPackage = try! AcknowPackageDecoder().decode(from: packageData)

let customList = AcknowList(headerText: nil, acknowledgements: [
    Acknow(title: "Some Graphics", license: "License of the graphics")
], footerText: nil)

let combinedAcknowList = customList + listFromPackage

but not (because the acknowledgments property is a let instead of a var):

let url = Bundle.main.url(forResource: "Package", withExtension: "resolved")!
let data = try! Data(contentsOf: url)
var list = try! AcknowPackageDecoder().decode(from: data)
list.acknowledgments.append(Acknow(title: "Some Graphics", license: "License of the graphics"))

@ChaosCoder ChaosCoder marked this pull request as draft April 13, 2026 07:16
@ChaosCoder ChaosCoder changed the title Allow mutation of AcknowList and expose + operator Allow initialization and mutation of AcknowList Apr 13, 2026
@ChaosCoder ChaosCoder marked this pull request as ready for review April 13, 2026 07:36
@vtourraine

Copy link
Copy Markdown
Owner

Hello Andreas, and thanks a lot for preparing this pull request!

I agree this would be a useful change. There’s just one aspect I would like to preserve as-is: the properties being constants (let) instead of variables. I think you can still achieve the same outcome, using the public initializer or the + operator. Could you please roll this back before I merge, or let me know if I’m missing something?

@ChaosCoder

Copy link
Copy Markdown
Contributor Author

Done.

I think the API of your library would improve by using var for the properties (as AcknowList is a struct), you can read about pros and cons here: https://swiftbysundell.com/articles/let-vs-var-for-swift-struct-properties/#is-immutability-always-the-answer or https://forums.swift.org/t/to-var-or-let-struct-properties/52363, but I am not gonna argue here as it is your choice.

@ChaosCoder ChaosCoder changed the title Allow initialization and mutation of AcknowList Allow initialization and addition of AcknowList Apr 14, 2026
@vtourraine vtourraine merged commit 49a42e2 into vtourraine:main Apr 14, 2026
1 check passed
@vtourraine

Copy link
Copy Markdown
Owner

I sincerely appreciate your feedback on this. I’ll stick to the current approach for now, but I’ll keep an open mind in case it needs revising. Thank you!

@vtourraine

Copy link
Copy Markdown
Owner

Release as version 3.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants