Created
July 9, 2014 18:17
-
-
Save ijoshsmith/ce119234407d0d9c2b91 to your computer and use it in GitHub Desktop.
Having some fun with the marshal operator in Swift
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
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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! :)