Search code examples
swiftoperatorsswift3tilde

What does ~> (tilde greater than) mean in this Swift code?


I am converting code that is not mine to swift 3.0 and there are some lines I don't understand that are being flagged by the compiler:

public func setupAppearance()
{
    if let delegate = delegate
    {
        firstWeekday~>delegate.firstWeekday?()
        dayOfWeekTextColor~>delegate.dayOfWeekTextColor?()
        dayOfWeekTextUppercase~>delegate.dayOfWeekTextUppercase?()
        dayOfWeekFont~>delegate.dayOfWeekFont?()
        weekdaySymbolType~>delegate.weekdaySymbolType?()
    }
}

NOTE this is not -> (dash, greater than) but ~> (tilde, greater than)

I did find this question: What is the ~> (tilde greater than) operator used for in Swift? but did not find it very helpful.

Can someone point me to docs on how to read this? Unfortunately google, stackoverflow and github can't search for ~>.

Thanks

Greg


Solution

  • I believe the original developer was using Swift custom operator for Thread Marshalling by iJoshSmith.

    func ~> <R> (
        backgroundClosure: () -> R,
        mainClosure:       (result: R) -> ())
    {
        dispatch_async(queue) {
            let result = backgroundClosure()
            dispatch_async(dispatch_get_main_queue(), {
                mainClosure(result: result)
            })
        }
    }