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
sv
1,244 PointsCannot Build
I have been proceeding down the Treehouse IOS path and had no issues but I have run into an issue that I can no longer build. I get a ton of really strange errors. I did some research and it said to try the latest version - I downloaded 6.3 Beta -not luck. I also downloaded all of the source files from Tree House and tried to build off of those and got the same error. Very frustration - any ideas?
Here is a screen shot of the error: http://note.io/1vkQVzc
12 Answers
Chris Shaw
26,676 PointsI could only find 3 issues with the code using Xcode 6.1.1, they are as follows.
var iconName = UIImage(named: imageName)
return iconName
Changes to the following as UIImage instances are now optional types.
var iconName = UIImage(named: imageName)
return iconName!
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in
if (error == nil) {
let dataObject = NSData(contentsOfURL: location)
let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject, options: nil, error: nil) as NSDictionary
let currentWeather = Current(weatherDictionary: weatherDictionary)
println(currentWeather.currentTime!)
}
})
Changes to the following as NSURL and NSData instances are also optional types.
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in
if (error == nil) {
let dataObject = NSData(contentsOfURL: location)
let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
let currentWeather = Current(weatherDictionary: weatherDictionary)
println(currentWeather.currentTime!)
}
})
Looking at this it might not seem apparent as to what has changed but if you look closely iconName now has a bang after it, as well as forecastURL and dataObject, the reason for the bang is so we can unwrap the object to reveal it's true type.
Aside from that the project works perfectly fine.
Chris Shaw
26,676 PointsHi,
You simply need to unwrap the UIImageView object by adding a bang to your return statement.
return image!
For errors such as these you can click on the small red circle in the gutter and that will tell you what needs to change in order for your code to work, it doesn't always work in certain situations but for this it will work fine.
Happy coding!
sv
1,244 PointsChris,
Thanks for the quick reply but I think it goes way beyond that - there are a ton of errors and I believe it is a code issue of some sort as this is the code directly from team tree house (I.e. not the code I typed). Here is another screen shot that illustrates it: http://note.io/19aeGp4
Chris Shaw
26,676 PointsWithout been able to see your code it's impossible to say what's wrong, if you could zip up your project folder, upload it to somewhere such as Dropbox I can take a look and assist you from there.
sv
1,244 PointsChris,
Thanks for the quick reply but I think it goes way beyond that - there are a ton of errors and I believe it is a code issue of some sort as this is the code directly from team tree house (I.e. not the code I typed). Here is another screen shot that illustrates it: http://note.io/19aeGp4
sv
1,244 PointsChris - it is the project code downloaded from treehouse - Stormy_s4v1.zip.
Steve Hunter
57,712 PointsCome out of the debugger and look at the file structure - which lines of code are causing these problems. It isn't a Treehouse issue else we'd all have the same problems so we should be able to figure out the problem - but looking at the errors in isolation will not help us.
Looking at the first screen shot, I agree with Chris Upjohn - just add a ! or you can streamline that bit of code to be:
return UIImage(named: imageName)!
If you have other errors, try the above and then post screen shots of your code so we can see where the error is.
Steve.
Steve Hunter
57,712 PointsI found that the later Xcode versions did need a tweak here and there as to where the bang needed placing. I'm pretty sure you've identified both those scenarios so you should be good to go from there.
Treehouse can't update every video immediately a change occurs in Swift - they happen constantly! The teacher's notes are usually informative else just ask in here. You've got there on your own which is cool!
Chris Shaw
26,676 PointsXcode 6.3 does need changes but both Amit Bijlani and Pasan Premaratne always stress that you should be using stable releases as they will give you better consistency with the course, while this it not 100% true with the iOS courses here on TH mainly due to the major changes in Xcode 6.1 following along is much better than 6.2 and 6.3.
Pasan Premaratne
Treehouse TeacherHey sigmundvandammesigmundvandamme
As Chris Upjohn suggests, we don't really endorse using Betas since there are lots of issues that may or may not be code related. In your case I think it's because you haven't converted from Swift 1.1 to Swift 1.2 (Xcode 6.3b includes a lot of changes to the Swift language). To automatically do that Go to Edit > Convert > Convert to Swift 1.2
This will initially show a bunch of errors but if you build and run the app again it should go away.
Glad to hear you got the problems resolved though! Mostly posting this for anyone else who runs into the same issue.
sv
1,244 PointsPasan,
I am still having difficulty (both with the 6.3 and convert) as well as trying the changes outlined. Is there an updated source code file I can look at to see if that loads?
Thanks,
-Sig
Pasan Premaratne
Treehouse TeacherI'm working on refreshing this course so it takes in to account the changes to Swift/Xcode. In the mean time, would you be able to email me your project or create a repository on Github and link me to it?
sv
1,244 PointsSure - what is the best email to use?
sv
1,244 PointsSent
Pasan Premaratne
Treehouse Teachersigmundvandammesigmundvandamme,
So I downloaded the project files that you sent me and the files from the direct course link and I got a different set of errors for both :/ In the case of the direct download, the errors were generated by updates to the Swift language and Xcode solved them automatically for me. If you click the red circle with the white dot in the gutter, Xcode suggests fixes...that solved all the issues on my end and I was able to build the project quite easily.
With the zip file you sent me however, I'm not entirely sure what's going on..but Xcode doesn't seem to recognize that Int, String and so on are actually Swift types. Need to look into this further...
