Skip to content

Instantly share code, notes, and snippets.

@StewartLynch
Created February 16, 2023 00:54
Show Gist options
  • Save StewartLynch/9f4e949382f37dec7d26d50d95abce9b to your computer and use it in GitHub Desktop.
Save StewartLynch/9f4e949382f37dec7d26d50d95abce9b to your computer and use it in GitHub Desktop.
import SwiftUI
struct PreviewLocation: ViewModifier {
enum LocationDir {
case documentsDirectory
case applicationSupportDirectory
}
let directory: LocationDir
func body(content: Content) -> some View {
ZStack {
content
Group {
switch directory {
case .documentsDirectory:
Text(URL.documentsDirectory.path(percentEncoded: false))
case .applicationSupportDirectory:
Text(URL.applicationSupportDirectory.path(percentEncoded: false))
}
}
.textSelection(.enabled)
.padding()
.background(RoundedRectangle(cornerRadius: 10).fill(Color(.systemBackground).shadow(.drop(radius: 5))))
.padding()
}
}
}
extension View {
func showPreviewLocation(_ directory: PreviewLocation.LocationDir) -> some View {
modifier(PreviewLocation(directory: directory))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment