GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

frameProcessingCompletionBlock in swift

Open westymatt opened this issue 12 years ago • 4 comments

    filter!.frameProcessingCompletionBlock({ (filter: GPUImageOutput!, frameTime: CMTime) in
        weakUIElementInput?.update()
    })

I keep getting "missing argument for parameter #2"

westymatt avatar Aug 07 '14 18:08 westymatt

    weak var weakUIElementInput = uiElementInput
    filter!.frameProcessingCompletionBlock? { (filter: GPUImageOutput!, frameTime: CMTime) -> Void in
        weakUIElementInput?.update()
    }

Trying this now

westymatt avatar Aug 08 '14 02:08 westymatt

You're setting a block, so you need to use an equals sign there to assign your closure:

filter.frameProcessingCompletionBlock = { (currentFilter, frameTime) in
    // Run whatever
}

BradLarson avatar Aug 08 '14 03:08 BradLarson

Just a heads up, that doesn't work. At least not in xcode 6 beta 4.

The only syntactical variation I got to work at all was this.

    weak var weakUIElementInput = uiElementInput
    func updater(filter: GPUImageOutput!, frameTime: CMTime) -> Void {
        weakUIElementInput?.update()
    }
    filter!.frameProcessingCompletionBlock = updater

westymatt avatar Aug 08 '14 15:08 westymatt

Really? The exact same syntax as I posted above worked in a Swift playground from beta 3 - beta 5 for me. It's valid syntax for setting a closure with the two inputs required, and I verified that it fired properly.

You might need to unwrap your optional filter in your case:

filter!.frameProcessingCompletionBlock = { (currentFilter, frameTime) in
    // Run whatever
}

but that's perfectly valid closure syntax. Check to make sure you typed this right.

BradLarson avatar Aug 08 '14 16:08 BradLarson