Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does --> (dash dash greater than) operator means in Swift

Tags:

swift

I look at the source code of GPUImage2

    picture = PictureInput(image:UIImage(named:"WID-small.jpg")!)
    filter = SaturationAdjustment()
    picture --> filter --> renderView
    picture.processImage()

What does --> do?

like image 927
Kokizzu Avatar asked Feb 06 '23 00:02

Kokizzu


1 Answers

This is an operator declared to add a destination target to the source.

infix operator --> : AdditionPrecedence
//precedencegroup ProcessingOperationPrecedence {
//    associativity: left
////    higherThan: Multiplicative
//}
@discardableResult public func --><T:ImageConsumer>(source:ImageSource, destination:T) -> T {
    source.addTarget(destination)
    return destination
}

The function is declared in the pipeline.swift file

The addTarget function is also pretty self descriptive.

public func addTarget(_ target:ImageConsumer, atTargetIndex:UInt? = nil) {
    if let targetIndex = atTargetIndex {
        target.setSource(self, atIndex:targetIndex)
        targets.append(target, indexAtTarget:targetIndex)
        transmitPreviousImage(to:target, atIndex:targetIndex)
    } else if let indexAtTarget = target.addSource(self) {
        targets.append(target, indexAtTarget:indexAtTarget)
        transmitPreviousImage(to:target, atIndex:indexAtTarget)
    } else {
        debugPrint("Warning: tried to add target beyond target's input capacity")
    }
}

Edit as other have said, the operator is custom to that project, and does not come builtin with the swift language as of Mar-29-2018

like image 70
Just a coder Avatar answered Feb 17 '23 10:02

Just a coder