Swiftpack.co -  YOCKOW/SwiftTemporaryFile as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
SwiftTemporaryFile provides functions related to temporary files.
.package(url: "https://github.com/YOCKOW/SwiftTemporaryFile.git", from: "4.0.4")

What is SwiftTemporaryFile?

SwiftTemporaryFile provides functions related to temporary files. It was originally written as a part of SwiftCGIResponder.


  • Swift 5
  • macOS(>=10.15) or Linux




import Foundation
import TemporaryFile

let tmpFile = TemporaryFile()
try! tmpFile.write(contentsOf: "Hello, World!".data(using:.utf8)!)
try! tmpFile.seek(toOffset: 0)
print(String(data: try! tmpFile.readToEnd()!, encoding: .utf8)!) // Prints "Hello, World!"
try! tmpFile.copy(to: URL(fileURLWithPath: "/my/directory/hello.txt"))

You can explicitly close the temporary file by calling `try tmpFile.close()`,
though all of the temporary files are automatically closed at the end of program.
import TemporaryFile

// You can pass a closure:
TemporaryFile { (tmpFile: TemporaryFile) -> Void in
  try! tmpFile.write(contentsOf: "Hello, World!".data(using:.utf8)!)
  // ... 
} // Automatically closed.


MIT License.
See "LICENSE.txt" for more information.


Stars: 0
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Use `FileHandleProtocol`.
1 year ago

TemporaryFile is no longer a subclass of FileHandle.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API