The swift-mime library can convert file extensions into possible MIME types.
You can use the command line utility to convert file extensions into file MIME types on the fly.
$ git clone https://github.com/BinaryBirds/swift-mime.git && cd swift-mime
$ make install
$ mime txt
$ # => text/plain
You can use the Swift Package Manager as usual:
.package(url: "https://github.com/binarybirds/swift-mime", from: "1.0.0"),
.product(name: "MIME", package: "swift-mime"),
import MIME
let mime = MIME()
let result = mime.getType(for: "txt")
print(result) // => text/plain