Skip to content

Callback is getting triggered twice in SwiftUI project  #23

@aryamansharda

Description

@aryamansharda

Hi, I'm using this library in a brand new vanilla SwiftUI project and anytime I make a change to a file, the callback is getting triggered twice:

import FileWatcher
class ContentScreenViewModel: ObservableObject {
    let filewatcher = FileWatcher(["/Users/aryamansharda/Documents/test.md"])

    init() {
        filewatcher.start() // start monitoring
        filewatcher.callback = { event in
            print("Something happened here: " + event.path)
        }
    }
}

struct ContentView: View {
    @StateObject var viewModel = ContentScreenViewModel()

    var body: some View {
        VStack {
            Text("Hello, world!")
        }
        .padding()
    }
}

This is the entirety of the program's code and any time I make a change to test.md, I see this in the Debugger:

Something happened here: /Users/aryamansharda/Documents/test.md
Something happened here: /Users/aryamansharda/Documents/test.md

When I use event.description in the print statement, it's showing that the file was renamed even though only its contents were changed:

The file /Users/aryamansharda/Documents/test.md was renamed
The file /Users/aryamansharda/Documents/test.md was created

For other files, both lines mention renamed:

The file /Users/aryamansharda/Documents/calc/.git/HEAD was renamed
The file /Users/aryamansharda/Documents/calc/.git/HEAD was renamed

Is this expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions