Skip to content

Instantly share code, notes, and snippets.

@ijoshsmith
Created July 9, 2014 18:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ijoshsmith/ce119234407d0d9c2b91 to your computer and use it in GitHub Desktop.
Save ijoshsmith/ce119234407d0d9c2b91 to your computer and use it in GitHub Desktop.
Having some fun with the marshal operator in Swift
import UIKit
// The marshal operator is reviewed in this blog post…
// http://ijoshsmith.com/2014/07/05/custom-threading-operator-in-swift/
// Don't ever do something this ridiculous in a real app!
func printMarshalOperator()
{
{p("M")}
~> {p("O")};
{p("A")} ~> {p("P")};
{p("R")} ~> {p("E")}; {p("S")} ~> {p("R")};
{p("H")} ~> {p("A")}; {p("A")} ~> {p("T")};
{p("L")} ~> {p("O")};
{p(" ")}
~> {p("R")};
}
func p(message: String) {
dispatch_async(dispatch_get_main_queue()) { print(message) }
}
class ViewController: UIViewController
{
@IBAction func handleButton(sender: AnyObject)
{
// Prints MARSHAL OPERATOR to the console
printMarshalOperator()
}
}
@ColinEberhardt
Copy link

very cool, and utterly bonkers!

@ijoshsmith
Copy link
Author

Thanks! :)

@dimitryz
Copy link

Ha! Clever!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment