Edit 3:
For other people getting this error, this is what happened here.
I originally created the IBAction for the slider as "numberOfSounds". I then created a class property called "numberOfSounds" and renamed the IBAction to "sliderValueChanged".
I expected the connection to automatically update the connection, BUT IT DOESN'T. So, since I dumbly used the same name for the variable, I missed the connection. See @rob accepted answer below for the telltale clue.
The solution was to delete the previous connection and control-drag from the slider in the storyboard to the sliderValueChanged IBAction in the ViewController.
Original question:
I'm getting this extremely common error and like many others, I'm having a hard time understanding the fix. Manipulating the slider causes a crash, which is this message:
2015-10-17 13:35:59.765 Test App[25969:2985698] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test_App.ViewController numberOfSounds:]: unrecognized selector sent to instance 0x7fc439e26740'
The breakpoint is on "numberOfSounds = Int(sender.value)".
import UIKit
import AVFoundation
class ViewController: UIViewController {
var numberOfSounds: Int = 0
@IBAction func sliderValueChanged(sender: UISlider) {
numberOfSounds = Int(sender.value)
}
}
I think I'm understanding something of the problem, being that despite numberOfSounds being a property of ViewController, its not available in the scope of sliderValueChanged.
I've read through the top 15-20 google searches for "unrecognized selector sent to instance" but still haven't found something that seems to answer the problem.
Thanks for the help.
Edit: (Adding more code)
class ViewController: UIViewController {
var numberOfSounds: Int = 0
@IBAction func sliderValueChanged(sender: UISlider) {
numberOfSounds = Int(sender.value)
}
@IBOutlet weak var numberOfSoundsLabel: UILabel!
@IBAction func PlaySound(sender: UIButton) {}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Edit 2: (Adding full stack trace)
2015-10-17 13:59:24.303 Test App[26230:3006546] -[Test_App.ViewController numberOfSounds:]: unrecognized selector sent to instance 0x7fedea730350 2015-10-17 13:59:24.313 Test App[26230:3006546] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test_App.ViewController numberOfSounds:]: unrecognized selector sent to instance 0x7fedea730350' * First throw call stack: ( 0 CoreFoundation 0x000000010a7d7f65 exceptionPreprocess + 165 1 libobjc.A.dylib
0x000000010c469deb objc_exception_throw + 48 2 CoreFoundation
0x000000010a7e058d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010a72df7a ___forwarding_ + 970 4 CoreFoundation 0x000000010a72db28 _CF_forwarding_prep_0 + 120 5 UIKit
0x000000010aff41fa -[UIApplication sendAction:to:from:forEvent:] + 92 6 UIKit 0x000000010b158504 -[UIControl sendAction:to:forEvent:] + 67 7 UIKit 0x000000010b1587d0 -[UIControl _sendActionsForEvents:withEvent:] + 311 8 UIKit 0x000000010b244770 -[UISlider beginTrackingWithTouch:withEvent:] + 1083 9 UIKit
0x000000010b15739d -[UIControl touchesBegan:withEvent:] + 136 10 UIKit 0x000000010b05e894 -[UIWindow _sendTouchesForEvent:] + 308 11 UIKit 0x000000010b05f691 -[UIWindow sendEvent:] + 865 12 UIKit
0x000000010b011752 -[UIApplication sendEvent:] + 263 13 UIKit
0x000000010afecfcc _UIApplicationHandleEventQueue + 6693 14 CoreFoundation 0x000000010a7040a1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 15 CoreFoundation 0x000000010a6f9fcc __CFRunLoopDoSources0 + 556 16 CoreFoundation 0x000000010a6f9483 __CFRunLoopRun + 867 17 CoreFoundation
0x000000010a6f8e98 CFRunLoopRunSpecific + 488 18 GraphicsServices
0x000000010ed6cad2 GSEventRunModal + 161 19 UIKit
0x000000010aff2676 UIApplicationMain + 171 20 Test App
0x000000010a5fc1ad main + 109 21 libdyld.dylib
0x000000010cfb092d start + 1 22 ???
0x0000000000000001 0x0 + 1 )
