Created
February 16, 2023 00:54
-
-
Save StewartLynch/9f4e949382f37dec7d26d50d95abce9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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