什么 - > (破折号大于)运算符意味着在Swift中

时间:2017-02-27 06:07:51

标签: swift

我查看了GPUImage2

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

-->做了什么?

2 个答案:

答案 0 :(得分:5)

这是一个声明为目标目标添加到源的运算符。

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

该函数在pipeline.swift文件

中声明

addTarget功能也非常具有自我描述性。

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")
    }
}
正如其他人所说的那样

编辑,运营商是该项目的自定义,并且自2009年3月29日起不会使用快速语言构建

答案 1 :(得分:3)

-->是特定于该项目的自定义运算符,用于将函数的管道链接在一起。它在framework/Source/Pipeline.swift的项目中使用中缀运算符定义。

相关问题