Last active
July 3, 2019 16:11
-
-
Save adamtarmstrong/5608741d454c71b2552d638cd7fa0e44 to your computer and use it in GitHub Desktop.
Issue updating @object in Class and reflecting in View
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
class ResultsObserver : NSObject, SNResultsObserving { //https://developer.apple.com/documentation/soundanalysis/analyzing_audio_to_classify_sounds | |
@ObjectBinding var whistle = Whistle() | |
func request(_ request: SNRequest, didProduce result: SNResult) { | |
... //removed for simplicity | |
if (classification.identifier == "my classification") { | |
print("Detected my classification - setting Object to true") //This shows in console (when appropriate) | |
DispatchQueue.main.async { | |
self.whistle.detected = true | |
} | |
} | |
}///end func | |
}///end class | |
...// All AVAudioEngine and SoundClassifier functions removed for simplicity | |
struct ViewDetail: View { | |
@ObjectBinding var whistle = Whistle() | |
var timer: Timer { | |
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) {_ in | |
DispatchQueue.main.async { | |
... //removed for simplicity | |
print("> checking whistle state, detected=\(self.whistle.detected)") //I see this in the console, every second, but ALWAYS shows false | |
} | |
} | |
} | |
... //removed all SwiftUI Views and Timer logic for simplicity | |
}///end struct | |
class Whistle: BindableObject { | |
var didChange = PassthroughSubject<Void, Never>() | |
var detected: Bool = false { | |
didSet { | |
didChange.send(()) | |
} | |
} | |
} | |
struct ContentView_Previews : PreviewProvider { | |
static var previews: some View { | |
ContentView(userData: UserData(users: testData), whistle: Whistle()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment