3) And here you have the really bug-inducing part of this game, of course: make courtesyClosure a property of _the model object_, and you have .dontTryThisAtHome(closure: myModel.courtesyClosure) – this could have captured anything and then been stored in the model, and suddenly you have state that is all over the place… did I say this was a BadIdea?

I don’t think that hardcoding the function you want to execute in response to a certain action _in the model (or an associated enum)_ is evil. Unnecessary, maybe, but not evil.
I’ve actually got a potential use case for this: I have a protocol in my app, and the individual classes could be very different, and rather than having a viewcontroller handling every single possible case, I considered encoding the models’ preferred behaviour _in the model itself_, and from there it was only a short step from ‘but what if text is not enough and I want to, say, show a custom alert?’, which in turn led to this post.

This is a pattern that could be abused badly, and I’d strongly recommend against capturing values from third parties.

3a) Add the following to the Lightweight structlet alertClosure = { ()->() in

let alert = NSAlert()
alert.messageText = "Proof of Concept"
alert.informativeText = "If you want to capture one of the properties, you need to have a proper initializer, which I am too lazy to write."
alert.addButton(withTitle: "OK")

alert.runModal()

}

3b) In viewDidLoad, set the Viewcontroller’s proofOfConcept variable to the following:

proofOfConcept = .dontTryThisAtHome(closure: thingy.alertClosure)

3c) NSAlert is a topic for another post, so this is just a quick-and-dirty version. Also note that if you run this code in viewDidLoad, you will never see the application’s window, which is … not ideal, but this is a proof of concept only; this is simply to show the possibilities you have.

Build and run. Instead of printing text to your console, you now get an alert popping up. This is advanced code branching, though not necessarily good application architecture.

I probably will never use this; I can see better architectural solutions for every potential use case I have considered (going through a large stack of app ideas and wondering whether this would solve any of my problems), but I thought it was an interesting thing that needed to be tried.