https://github.com/0xwdg/filepicker
FilePicker is a SwiftUI view modifier that allows you to open a file picker and open or save a file from the user's device.
https://github.com/0xwdg/filepicker
0xwdg filepicker ios macos swift swiftlang swiftpm swiftui
Last synced: about 2 months ago
JSON representation
FilePicker is a SwiftUI view modifier that allows you to open a file picker and open or save a file from the user's device.
- Host: GitHub
- URL: https://github.com/0xwdg/filepicker
- Owner: 0xWDG
- License: mit
- Created: 2025-01-31T18:24:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-06T19:24:44.000Z (over 1 year ago)
- Last Synced: 2025-03-25T18:19:18.479Z (over 1 year ago)
- Topics: 0xwdg, filepicker, ios, macos, swift, swiftlang, swiftpm, swiftui
- Language: Swift
- Homepage: https://0xwdg.github.io/FilePicker/
- Size: 302 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# FilePicker
FilePicker is a SwiftUI view modifier that allows you to open a file picker and open or save a file from the user's device.
[](https://swiftpackageindex.com/0xWDG/FilePicker)
[](https://swiftpackageindex.com/0xWDG/FilePicker)
[](https://swift.org/package-manager)

## Requirements
- Swift 5.9+ (Xcode 15+)
- iOS 15+, macOS 12+
## Installation (Pakage.swift)
```swift
dependencies: [
.package(url: "https://github.com/0xWDG/FilePicker.git", branch: "main"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "FilePicker", package: "FilePicker"),
]),
]
```
## Installation (Xcode)
1. In Xcode, open your project and navigate to **File** โ **Swift Packages** โ **Add Package Dependency...**
2. Paste the repository URL (`https://github.com/0xWDG/FilePicker`) and click **Next**.
3. Click **Finish**.
## Usage (Open file)
```swift
import SwiftUI
import FilePicker
struct ContentView: View {
// MARK: Filepicker
@State var filePickerOpen = false
@State var filePickerFiles: [URL] = []
var body: some View {
VStack {
Text("Open a file :)")
.padding()
Button("Open", systemImage: "square.and.arrow.down") {
filePickerOpen.toggle()
}
ForEach(filePickerFiles, id: \.self) { file in
Text(file.lastPathComponent)
}
}
.padding()
.filePicker(
isPresented: $filePickerOpen,
files: $filePickerFiles,
types: [.json, .text], // Optional (default: .json)
allowsMultipleSelection: false // Optional (default: false)
)
.onChange(of: $filePickerFiles.wrappedValue) { newValue in
print(newValue)
}
}
}
```
## Usage (Save file)
```swift
import SwiftUI
import FilePicker
struct ContentView: View {
// MARK: Filepicker
@State var filePickerOpen = false
var filePickerFileName = "test.txt"
var filePickerData = Data("Hello, World!".utf8)
var body: some View {
VStack {
Text("Save a file :)")
.padding()
Button("Save", systemImage: "square.and.arrow.up") {
filePickerOpen.toggle()
}
}
.padding()
.filePicker(
isPresented: $filePickerOpen,
fileName: filePickerFileName,
data: filePickerData,
types: [.text]
)
}
}
```
## Contact
๐ฆ [@0xWDG](https://bsky.app/profile/0xWDG.bsky.social)
๐ [mastodon.social/@0xWDG](https://mastodon.social/@0xWDG)
๐ฆ [@0xWDG](https://x.com/0xWDG)
๐งต [@0xWDG](https://www.threads.net/@0xWDG)
๐ [wesleydegroot.nl](https://wesleydegroot.nl)
๐ค [Discord](https://discordapp.com/users/918438083861573692)
Interested learning more about Swift? [Check out my blog](https://wesleydegroot.nl/blog/).