Once-a-year Black Friday deals are coming. Read more.
Give your simulator superpowers

RocketSim: An Essential Developer Tool
as recommended by Apple

Third-party libraries acknowledgments using a Settings bundle

Third-party libraries help developers build apps faster but often come with a license. The MIT license is likely the most common, but there are many others that, together, require you to acknowledge the usage of the library in return for getting free access.

I’m not going to dive deep into the details of each license type, but I will explain how you can add acknowledgments inside your app without much effort. We will use a Settings bundle to move all acknowledgments to the system settings level, not distracting regular usage inside your app.

Why you should add acknowledgments for 3rd party libraries

Open-source projects make it easy to add a new library to your app. You’ll be able to build apps faster by benefiting from new functionality out of 3rd party dependencies. Most of the libraries are free to use but do come with a license that you should respect.

A common license you’ll see is a so-called MIT license, which contains copy similar to the following quote:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

In other words, you gain permission to use the library as long as you include an acknowledgment for the library. At first, you might think it’s a lot of manual work to create an overview of the potentially many libraries your app uses. However, many tools simplify this process and automatically fetch licenses based on your Swift Packages file.

Stay updated with the best of Swift & SwiftUI

Join over 20,005 Swift developers in SwiftLee Weekly for exclusive tips and updates. Don’t miss out – subscribe now:

You can always unsubscribe, no hard feelings.

Creating a Settings bundle with acknowledgments for Swift Packages

Several open-source projects allow you to automatically generate a Settings bundle to show an overview of acknowledgments for the libraries your app uses. For example, this is a recording of the acknowledgments inside the WeTransfer app:

Showing 3rd-party Library acknowledgments inside the app’s settings.

It’s convenient to show acknowledgments inside the system Settings app as they will not be visible inside the app itself. Yet, you do fulfill the license requirement.

While many tools are available to generate acknowledgments, I used SwiftPackageList. It’s a well-maintained library, and it comes with several options to generate the license, including a build-tool plugin.

Deciding how to automate generation of acknowledgments

Before you start generating a Settings bundle, it’s important to ask yourself how you want to automate this process. While you might not add a new third-party library daily, it’s essential to consider updating acknowledgments when you do.

Many libraries on GitHub suggest using either a build-phase or build tool plugin to update the acknowledgments on every build. While this ensures you’ll never have an outdated acknowledgments section, you might slow down regular builds for unnecessary checks. In my experience, we’re only sometimes adding new libraries, so I decided to write a simple script that at least simplifies the effort to update acknowledgments.

It’s essential to realize this solution requires manual action. In other words, you need to find a way to remember to run the script when adding a new library to your app. You could consider executing a build-phase only when the Package.resolved file changed, but I decided not to optimize too far because we’re not adding a new library often. Our coding guidelines contain a section on 3rd-party libraries, which is a great place to note about running the acknowledgments script.

Creating a Shell script to update the Settings bundle

Before writing a script, I recommend executing the commands manually and ensuring you’ve setup your project correctly to show a custom Settings bundle.

We start by installing the SwiftPackageList library using the terminal and the following commands:

# Install https://github.com/FelixHerrmann/swift-package-list first using brew
# so we can continue to update our acknowledgments.
brew tap FelixHerrmann/tap
brew install swift-package-list

Followed by executing the library itself:

# Run the command to update the acknowledgments. These will be auto-generated based on your Package.swift file.
swift-package-list <your-project>.xcodeproj --output-type settings-bundle --requires-license --output-path <your-project>/Supporting\ Files/

There are a few points to note:

  • This command works for the WeTransfer project, but you might want to adjust it to your needs. Make sure to reference the project’s readme.
  • We like to move supporting files like a Settings.bundle to a Supporting Files subdirectory
  • The --requires-license argument ensures that libraries without a license can be skipped as there’s no acknowledgment needed.
  • All third-party libraries with a license you’ve added using Swift Package Manager will be acknowledged.

After running this command successfully, you can run your app and validate the outcome. Finally, you can move these commands in a new Shell file called update-acknowledgments.sh:

#!/bin/bash


# This is a script to update our Settings.bundle with up-to-date acknowledgments for any
# 3rd party dependencies. 
#
# These acknowledgements will be available inside Settings -> <Your App> -> Acknowledgments and are required
# since many 3rd party dependencies come with an MIT license that allows free usage, as long as the libraries
# are acknowledged.
#
# Usage:
# - Run this script from inside the project's root. E.g. `./scripts/update-acknowledgments.sh`

# Install https://github.com/FelixHerrmann/swift-package-list first using brew
# so we can continue to update our acknowledgments.
brew tap FelixHerrmann/tap
brew install swift-package-list

# Run the command to update the acknowledgments. These will be auto-generated based on our Package.swift file.
swift-package-list <Your Project>.xcodeproj --output-type settings-bundle --requires-license --output-path <Your Project>/Supporting\ Files/

The last task is updating your coding guidelines to ensure this script runs whenever a new dependency gets added.

Conclusion

Third-party libraries are convenient and allow you to build apps faster. Many of those libraries come with a license that allows free usage as long as your app includes an acknowledgment. We can automatically create a section inside our app’s system settings to show a list of acknowledgments for each Swift package library used.

If you like to improve your workflow, even more, check out the workflow category page. Feel free to contact me or tweet to me on Twitter if you have any additional tips or feedback.

Thanks!

 
Antoine van der Lee

Written by

Antoine van der Lee

iOS Developer since 2010, former Staff iOS Engineer at WeTransfer and currently full-time Indie Developer & Founder at SwiftLee. Writing a new blog post every week related to Swift, iOS and Xcode. Regular speaker and workshop host.

Are you ready to

Turn your side projects into independence?

Learn my proven steps to transform your passion into profit.