TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Day 53 project13 Thread 1: "-[UISlider doubleValue]: unrecognized selector sent to instance 0x156b0b600"

Forums > 100 Days of Swift

Hi everyone,

when I choose image from library and slide the intensity changed I getting this error : Thread 1: "-[UISlider doubleValue]: unrecognized selector sent to instance 0x156b0b600"

import CoreImage
import UIKit

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    @IBOutlet var Intensity: UISlider!
    @IBOutlet var imageView: UIImageView!
    var currentImage: UIImage!

    var context: CIContext!
    var currentFilter: CIFilter!

    override func viewDidLoad() {
        super.viewDidLoad()

        title = "Instafilter"
        navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(importPicture))

        context = CIContext()
        currentFilter = CIFilter(name: "CISepiaTone")
        applyProcessing()

    }

    @objc func importPicture() {
        let picker = UIImagePickerController()
        picker.allowsEditing = true
        picker.delegate = self
        present(picker, animated: true)
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        guard let image = info[.editedImage] as? UIImage else {return}

        dismiss(animated: true)

        currentImage = image

        let bigenImage = CIImage(image: currentImage)
        currentFilter.setValue(bigenImage, forKey: kCIInputImageKey)
    }

    @IBAction func changeFilter(_ sender: Any) {
    }

    @IBAction func save(_ sender: Any) {

    }
    @IBAction func intensityChanged(_ sender: Any) {
        applyProcessing()
    }

    func applyProcessing() {
        guard let image = currentFilter.outputImage else { return }
        currentFilter.setValue(Intensity, forKey: kCIInputIntensityKey)

        if let cgImage = context.createCGImage(image, from: image.extent) {
            let processedImage = UIImage(cgImage: cgImage)
            imageView.image = processedImage
        }
    }
}

3      

Hi there! I cannot say for sure but the reason might in IBAction. Try to change it instead of Any to UISlider

@IBAction func intensityChanged(_ sender: UISlider) {
    applyProcessing()
  }

and make sure Slider in storyboard is connected exactly to this IBAction.

UPD or more probably you forgot to use values in your Intensity instance.

currentFilter.setValue(Intensity.value, forKey: kCIInputIntensityKey)

3      

Thank you @ygeras

I forgot use values in the Intensity instance.

3      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.