"This Class Is Not Key Value Coding-Compliant" Using Coreimage

This class is not key value coding-compliant using CoreImage

Key value coding-compliant properties must be marked as dynamic

dynamic var inputImage : CIImage?

and in Swift 4 even as @objc

@objc dynamic var inputImage : CIImage?

this class is not key value coding-compliant when using SideMenu pod in interface builder

The “this class is not key value coding-compliant” error almost always means that you are trying to set a property of a custom subclass in your storyboard or XIB file in Interface builder, but forgot to change the class of your object to the custom class. It's easy to get this error if you use "user defined runtime attributes" to set properties on your objects, but don't set the class of the object correctly.

I'd have to look at the project - and specifically it's Storyboards/XIB files, to find the problem, but that's very likely what's going on.

˜this class is not key value coding-compliant for the key˜ when creating a new Target

I found what was wrong. Something really simple that I can't believe it took me so long to figure out. The first view controller had a module selected (when it was not supposed to have any). For that reason, whenever I ran a different target it would not find the view's elements.

How to use CIFilter sunbeamsGenerator in Swift 5 and iOS 13?

The CISunbeamsGenerator doesn't need an input image – it will generate a sunbeam effect (hence the name) that you can use to, for instance, blend over another image.

When you call ciImage.applyingFilter(...) it will try to assign the image as inputImage to the given filter. But generators don't have that property, hence the error.

You can do something like this instead:

public func withSunFilter() -> UIImage {
let ciImage = CIImage(image: self)!
let filter = CIFilter.sunbeamsGenerator()
let sunbeam = filter.outputImage!
let output = sunbeam.composited(over: ciImage)
return output.uiImage
}

Check the parameters of CISumbeamsGenerator to see what you can do with it.

How to Troubleshoot Playground CIFilter Error Message

The playground does not like that inputImage is not declared as @objc. If you change this:

class CRTWarpFilter: CIFilter
{
var inputImage: CIImage?

To this:

class CRTWarpFilter: CIFilter
{
@objc var inputImage: CIImage?

It's going to work fine.

Here's your code updated to Xcode 11 and Swift 5

//: ## Barrel Distortion Warp Filter

import UIKit
import CoreImage

//: ### Warp Kernel

class CRTWarpFilter: CIFilter
{
@objc var inputImage: CIImage?
var bend: CGFloat = 3.2

let crtWarpKernel = CIWarpKernel(source: """
kernel vec2 crtWarp(vec2 extent, float bend)
{
vec2 coord = ((destCoord() / extent) - 0.5) * 2.0;

coord.x *= 1.0 + pow((abs(coord.y) / bend), 2.0);
coord.y *= 1.0 + pow((abs(coord.x) / bend), 2.0);

coord = ((coord / 2.0) + 0.5) * extent;

return coord;
}
""")

override var outputImage: CIImage?
{
if let inputImage = inputImage, let crtWarpKernel = crtWarpKernel
{
let arguments = [CIVector(x: inputImage.extent.size.width,
y: inputImage.extent.size.height),
bend] as [Any]

let extent = inputImage.extent

return crtWarpKernel.apply(extent: extent,
roiCallback:
{(index, rect) in return rect},
image: inputImage,
arguments: arguments)
}
return nil
}
}

let ciContext = CIContext()

func imageFromCIImage(source: CIImage) -> UIImage
{
let cgImage = ciContext.createCGImage(source, from: source.extent)

return UIImage(cgImage: cgImage!)
}

//: ### Swift Implementation of barrel warp kernel

//: `x` and `y` are pixel coordinates
let x = 65.0
let y = 55.0

//: `width` and `height` are extent
let width = 900.0
let height = 300.0

//: `crtWarpKernel` mechanics in Swift
var coordX = ((x / width) - 0.5) * 2.0
var coordY = ((y / height) - 0.5) * 2.0

coordX *= 1 + pow((abs(coordY) / 3.2), 2.0)
coordY *= 1 + pow((abs(coordX) / 3.2), 2.0)

coordX = ((coordX / 2.0) + 0.5) * width
coordY = ((coordY / 2.0) + 0.5) * height

// ----

let backgroundImage = CIFilter(name: "CICheckerboardGenerator",
parameters: [
"inputColor0":
CIColor(red: 0.1, green: 0.1, blue: 0.1),
"inputColor1":
CIColor(red: 0.15, green: 0.15, blue: 0.15),
"inputCenter": CIVector(x: 0, y: 0),
"inputWidth": 50])!
.outputImage!.cropped(to: CGRect(x: 1, y: 1,
width: width - 2,
height: height - 2))
.composited(over: CIImage(color: CIColor(red: 0, green: 0, blue: 0)))
.cropped(to: CGRect(origin: CGPoint.zero,
size: CGSize(width: width, height: height)))

let blueBox = CIImage(color: CIColor(red: 0.5, green: 0.5, blue: 1, alpha: 0.7))
.cropped(to: CGRect(origin: CGPoint(x: coordX - 5, y: coordY - 5),
size: CGSize(width: 10, height: 10)))

let redBox = CIImage(color: CIColor(red: 1, green: 0, blue: 0, alpha: 0.7))
.cropped(to: CGRect(origin: CGPoint(x: x - 5, y: y - 5),
size: CGSize(width: 10, height: 10)))

let warpFilter = CRTWarpFilter()
warpFilter.inputImage = backgroundImage

let composite = CIFilter(name: "CIAdditionCompositing",
parameters: [
kCIInputBackgroundImageKey: warpFilter.outputImage,
kCIInputImageKey: blueBox])!
.outputImage!
.applyingFilter("CIAdditionCompositing",
parameters: [kCIInputBackgroundImageKey: redBox])

let result = composite


Related Topics



Leave a reply



Submit