“该类别不符合键值编码".使用CoreImage

编程入门 行业动态 更新时间:2024-10-26 20:21:52
本文介绍了“该类别不符合键值编码".使用CoreImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在Swift中开发一个简单的MacOS 命令行应用程序.我创建了一个自定义的CoreImage过滤器,使用起来很麻烦.该代码可以很好地编译,但是在运行时会退出,并显示以下错误:

I'm working on a simple MacOS command-line application in Swift. I created a custom CoreImage filter and having troubles to use it. The code compiles just fine but when it runs it exits with the following error:

***由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]: 此类与键inputImage的键值编码不兼容.'

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key inputImage.'

在此问题上的任何帮助将不胜感激.尝试在SO上寻找答案,但是不幸的是,由于我的应用程序没有使用Storyboards或Outlets(它是纯命令行),所以我无能为力.

Any help with this issue would be greatly appreciated. Tried searching for an answer on SO but since my application does not use Storyboards or Outlets (it's pure command-line) unfortunately I couldn't help myself.

我的程序在这一行中断:

My program breaks on this line:

filter.setValue(inputImage, forKey: kCIInputImageKey)

这是我正在使用的代码:

Here's the code I'm using:

class CustomFilter:CIFilter { var inputImage:CIImage? let kernelString = CIKernel(string: "kernel vec4 chromaKey( __sample s) { \n" + " vec4 newPixel = s.rgba;" + " newPixel[0] = 0.0;" + " newPixel[2] = newPixel[2] / 2.0;" + " return newPixel;\n" + "}" ) override var outputImage:CIImage! { guard let inputImage = inputImage else { return nil } let extent = inputImage.extent let blur = kernelString?.apply( withExtent: extent, roiCallback: { (index, rect) in return rect }, arguments: [inputImage]) return blur!.cropping(to: extent) } } let filter = CustomFilter() filter.setValue(inputImage, forKey: kCIInputImageKey) // it breaks here guard let result = filter.outputImage else { return nil } return result

推荐答案

键值编码兼容属性必须标记为dynamic

Key value coding-compliant properties must be marked as dynamic

dynamic var inputImage : CIImage?

,在Swift 4中,甚至是@objc

and in Swift 4 even as @objc

@objc dynamic var inputImage : CIImage?

更多推荐

“该类别不符合键值编码".使用CoreImage

本文发布于:2023-11-26 17:36:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不符合   键值   类别   CoreImage   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!