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 trialAndrew Bauml
2,181 PointsWhile the update of Xcode requires ! or ? for downcasting, why do I still get a fatal error?
I've done the fix-it to add an "!" to "as", made sure that the UILabel is referenced to artists, and it still says that it unwraps nil. This is the error; fatal error: unexpectedly found nil while unwrapping an Optional value Printing description of playlistDetailController: (Algorhythm.PlaylistDetailViewController?) playlistDetailController = 0x00007fb6cb725800 { UIKit.UIViewController = { UIKit.UIResponder = { ObjectiveC.NSObject = {} } } buttonPressLabel = nil segueLabelText = "" }
//and stops at
segue UIStoryboardSegue 0x00007fb6cb718010 0x00007fb6cb718010 sender AnyObject? Some Some self Algorhythm.PlaylistMasterViewController 0x00007fb6cb42f740 0x00007fb6cb42f740 playlistDetailController Algorhythm.PlaylistDetailViewController? 0x00007fb6cb725800 0x00007fb6cb725800
Thank you for any help!
11 Answers
Polidoros Karampougikis
1,820 PointsFor those who still get errors check once again the IBOutlet of the label, if it is correctly connected.
Unsubscribed User
6,281 PointsAndrew Baumi, can you tell me what the problem was? I simply can't figure it out, and now i've seen the clip 3 times and all my code matches.
Jiasheng Qu
1,959 PointsI got the same problem. But once I change my code to
playListDetailController.segueLabelText = "Yay!You Pressed the button."
then it became fine.
Unsubscribed User
6,281 PointsHi Jiasheng Qu
I still have the error. When i launch the APP and press the button, it says that there is an error in the code:
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
Can you please send me your code, so that I can compare?
Greetings
Andrew Bauml
2,181 PointsHey Thomas, sorry it took so long to get back to you. My issue was that in the playlistMasterVC I had playlistDetailViewController.buttonLabelPress.txt = "Yay! You pressed the button!" and needed playlistDetailController.segueLabelText = "Yay! You pressed the button!"
It looks like you might have an extra curly brace at the bottom of your PlaylistMasterViewController
Unsubscribed User
6,281 PointsHi Andrew Bauml. If I remove one of my curlybracers it gives me and error. Would you mind to show me all of your code?
Tanks for the response :)
Jeff Stern
770 PointsI need help! My partner and I have been reading all of your revisions, and they don't seem to work. Here is our code.
// // ViewController.swift // Algorhythm // // Created by Michela Burns on 7/28/15. // Copyright (c) 2015 Michela Burns and Kai Wong. All rights reserved. //
import UIKit
class PlaylistMasterViewController: UIViewController { @IBOutlet weak var buttonPressLabel:UILabel! var segueLabelText: String = ""
@IBOutlet weak var aButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
aButton.setTitle("Press me!", forState: .Normal)
//buttonPressLabel.text=segueLabelText
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showPlaylistDetail"
{
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
playlistDetailController.buttonPressLabel.text = "Yay! You pressed the button!";
}
}
}
// // PlaylistDetailViewController.swift // Algorhythm // // Created by Michela Burns on 7/28/15. // Copyright (c) 2015 Michela Burns and Kai Wong. All rights reserved. //
import UIKit
class PlaylistDetailViewController: UIViewController {
@IBOutlet weak var buttonPressLabel: UILabel!
var segueLabelText: String = ""
override func viewDidLoad() {
super.viewDidLoad()
buttonPressLabel.text = segueLabelText
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Marlon Henry
6,885 PointsCan I get a look at the code itself? Did you implement a nil check if you get back some bad/nil data?
Andrew Bauml
2,181 Points//MasterView import UIKit
class PlaylistMasterViewController: UIViewController {
@IBOutlet weak var aButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
aButton.setTitle("Press Me", forState: .Normal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showPlaylistDetail" {
let playlistDetailController = segue.destinationViewController as!
PlaylistDetailViewController
playlistDetailController.buttonPressLabel.text = "Yay, you pressed the button":
//DetailView
import UIKit
class PlaylistDetailViewController: UIViewController {
@IBOutlet weak var buttonPressLabel: UILabel!
var segueLabelText: String = ""
override func viewDidLoad() {
super.viewDidLoad()
buttonPressLabel.text = segueLabelText
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Thank you Marlon
Deepa Laxmi
3,035 PointsCan you please help me out? I am also facing the same problem. thanks in advance
Marlon Henry
6,885 PointsWhat's the else part of the statement? So far I'm not seeing a issue
Kyle DuFrene
4,217 PointsI had the same issue where the fix it was to add an !, but after I did that the issue was resolved and everything seems to work normally. My code is identical to yours though, so I am not sure what your bug is.
Kenton Raiford
5,101 PointsI have the same issue and I added the ! but my code still isn't working. Did you fix it?
Andrew Bauml
2,181 PointsYes, watch the video very closely. There's one part that I had missed about rewriting something on the playlistDetailController. Good luck, you'll laugh when you realize how blatant it was!
Kenton Raiford
5,101 PointsI did everything he said in the video and my app is still crashing when I click the button.
Deepa Laxmi
3,035 Pointsdid you fix your problem? I am also facing the same problem.
Deepa Laxmi
3,035 Pointsdid you fix your problem? I am also facing the same problem.
Unsubscribed User
6,281 PointsUnsubscribed User
6,281 PointsPolidoros.. I have checked many times.
Can you have a look at my code for me?
thank you
Polidoros Karampougikis
1,820 PointsPolidoros Karampougikis
1,820 PointsThomas your code looks fine to me, i used the same exact code, the problem was that when i right clicked on the label, i noticed that there was no IBOutlet connected, So i deleted the @IBOutlet weak var buttonPressLabel: UILabel! and re-connected it using the control drag option. If it isn't your label, check your button then, something isn't correctly mentioned in the code.
Unsubscribed User
6,281 PointsUnsubscribed User
6,281 PointsPolidoros Karampougikis i reconnected the button, and yaay it worked. Atleast now it's not giving me an error when i run the app. Now it just shows both the "yay, you have pressed the button" and the "you haven't pressed the button". And it's not overwriteing:S
Polidoros Karampougikis
1,820 PointsPolidoros Karampougikis
1,820 PointsThomas, try deleting the IBOutlet of the Label and the Label itself and drag a new one in the middle and reconnect it like you did in the tutorial.
Unsubscribed User
6,281 PointsUnsubscribed User
6,281 PointsI did sir. But dont know what is wrong, I think i will do the course over again to get it right and get some more learning. Thanks, and heres an upvote