The Mime package provides you with a simple interface for parsing urls and file extensions to their appropriate mime types.
Mime is available via the Swift Package Manager which is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system and automates the process of downloading, compiling, and linking dependencies.
Once you have your Swift package set up, adding Mime as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [
.package(
url: "https://github.com/aplr/Mime.git",
.upToNextMajor(from: "1.0.0")
)
]
import Mime
let url = URL(string: "file:///tmp/vienna.png")!
guard let mime = Mime(url: url) else { return }
print(mime.mime) // image/png
print(mime.ext) // png
Documentation is available here and provides a comprehensive documentation of the library's public interface.
Mime is licensed under the MIT License.