Making a Simple Swift Observable

I’ve been practicing reactive programming recently mostly with SwiftBond and I’ve been enjoying it. I’ve mostly just worked with simple observing and binding. So, I thought how – if at all – could I do simple observing in Swift without using a reactive library, key-value observing, or NSNoticationCenter.

I was able to do it using closures, except that I’m running into an issue where I’m forced to make some properties immutable when I would rather not. Take a look at the project and let me know if you can help me with it. Ideally, I would like to be able to make my viewModel property of my ViewController as well as the alertOutput property of my viewModel constants. The issue is that the observe(onNext:) method of my viewModel is mutating. So, how could I do self.onNext = onNext in some other way? How could I make that method non-mutating? What could I do so that I could keep those two properties immutable?

Check out the project on GitHub. Take a look at the code and let me know if you can help.