UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out 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.