Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Chi Bong
Courses Plus Student 285 PointsSwift: Unrecognized Selector sent to instance
I am working on the module "Build a Simple iPhone App with Swift". On the section "Views and View Controllers" Whenever I click the button "Show Another Fun Fact" I get the error "unrecognized selector sent to instance"
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var funFactLabel: UILabel!
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.
}
@IBAction func showFunFact() {
funFactLabel.text = "Another Interesting Fact"
}
}
I can't figure out why it keeps crashing.
5 Answers

dungeonkeeperhf
3,272 PointsIt looks like an extra outlet is being used on the IB builder. Right click on both your uiElements in the IB and see if you have an extra outlet that doesn't link to anything.
William Crawford
4,319 PointsChi, You might jump ahead to the debugging section. What you typed looks good, but I fixed my broken app today, after watching the debugging section. You may also have an extra outlet, as I did, which does not show in the code. Just my experience. Bill

Daniel Templin
5,293 PointsIt's a little hard to tell without looking at exactly what you're looking at on your screen, but the first place I would probably look when it comes to something like an IBAction is the connections created in interface builder.
Selecting your view controller in Interface Builder and then going to the Connections Inspector (it's the circle with an arrow pointing to the left; if the right pane is hidden you will need to show it) should show you all of your outlets and actions and what they're connected to. I could check for duplicate actions and verify that under "Received Actions" at the bottom you have your button connected up.
One thing I have done in the past with buttons sending me strange errors is also to recreate the connections. In a larger project this of course would be much harder to do, but since there is so little code right now it may be a quick a dirty way to do it.

Soojin Ro
13,331 PointsI think your IBAction in the code and UIButton in your storyboard is not matched up correctly. (1) Just delete the current IBAction code (2) right click the UIButton in the storyboard -> delete anything linked to the button(click x circle) (3) reconnect the IBAction by ctrl-dragging the UIButton

Chi Bong
Courses Plus Student 285 PointsThanks everyone! It was an extra outlet that I discovered once I right clicked on "show another fun fact".