Skip to content

Commit ed22819

Browse files
Merge pull request #41 from YusukeHosonuma/improve-debug-modifier
improve: built-in modifier
2 parents 9b02263 + a6bed7b commit ed22819

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/SwiftUISimulator/DebugFilenameModifier.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import SwiftUI
99

1010
public extension View {
1111
func simulatorDebugFilename(_ file: StaticString = #file) -> some View {
12-
let filename = String(String(file).split(separator: "/").last ?? "")
13-
return modifier(DebugFilenameModifier(filename: filename))
12+
let name = String(String(file).split(separator: "/").last?.replacingOccurrences(of: ".swift", with: "") ?? "")
13+
return simulatorDebugFilename(name)
14+
}
15+
16+
func simulatorDebugFilename(_ name: String) -> some View {
17+
modifier(DebugFilenameModifier(filename: name))
1418
}
1519
}
1620

@@ -21,7 +25,7 @@ struct DebugFilenameModifier: ViewModifier {
2125
self.filename = filename
2226
}
2327

24-
@Environment(\.debugFilename) private var debugFilename
28+
@Environment(\.simulatorDebugFilename) private var debugFilename
2529

2630
func body(content: Content) -> some View {
2731
if debugFilename {
@@ -49,7 +53,7 @@ struct DebugFilenameEnvironmentKey: EnvironmentKey {
4953
}
5054

5155
public extension EnvironmentValues {
52-
var debugFilename: Bool {
56+
var simulatorDebugFilename: Bool {
5357
get {
5458
self[DebugFilenameEnvironmentKey.self]
5559
}

0 commit comments

Comments
 (0)