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 trialTurner Commercial Prods
6,409 PointsPrograms terminates at return UIImage in Icon.toImage()
I have been trying to debug this but I can't put my finger on it: I have simplified my toImage
function to the following:
enum Icon {
case ClearDay = "clear-day"
func toImage() -> UIImage? {
return UIImage(named: "\(self.rawValue).png")
}
}
But every time I run the app, it stops at this return statement. Even with the code exactly as it was in the video, I keep getting this error. If I, however, created a function toImageString()
, return the string and then construct my UIImage from that string, no error is thrown. Why is this?
func toImageName() -> String {
return "\(self.rawValue).png";
}
Update: even if I return nil
, which is allowed as it expects an optional, the same line is highlighted an my app terminates right then and there. The return statement seems to be the culprit, but I'm not seeing why.
I have also build a quick test case so I don't need to connect to the weather service, which goes like this:
var i = Icon.ClearDay;
println(i.toImageName())
// prints "clear-day.png"
var im = UIImage(named: i.toImageName());
// works
var im2 = i.toImage()
// Terminates, prints (lldb) in green, marks `return` line with green, when commented out the next line works as expected.
self.currentWeatherImage?.image = im;
KB Li
Courses Plus Student 625 PointsKB Li
Courses Plus Student 625 PointsThis is weird...It looks good to me, and I tried it in my project, it worked.
My guess is you accidentally added a breakpoint at the return line. Check if there is a blue arrow like thing next to you code. If so, drag the blue arrow in the code interface and drop, this will remove the breakpoint :)