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 trialCaleb Kleveter
Treehouse Moderator 37,862 PointsUse of unresolved identifier 'kCGGradientDrawsBeforeStartLocation'
In the code snippet for this video that you can find in the teachers notes, I have been getting this error
Use of unresolved identifier 'kCGGradientDrawsBeforeStartLocation'
What could be causing this? Here is the code:
override func drawRect(rect: CGRect) {
// Drawing code
// Background View
//// Color Declarations
let lightPurple: UIColor = UIColor(red: 0.377, green: 0.075, blue: 0.778, alpha: 1.000)
let darkPurple: UIColor = UIColor(red: 0.060, green: 0.036, blue: 0.202, alpha: 1.000)
let context = UIGraphicsGetCurrentContext()
//// Gradient Declarations
let purpleGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [lightPurple.CGColor, darkPurple.CGColor], [0, 1])
//// Background Drawing
let backgroundPath = UIBezierPath(rect: CGRectMake(0, 0, self.frame.width, self.frame.height))
CGContextSaveGState(context)
backgroundPath.addClip()
CGContextDrawLinearGradient(context, purpleGradient,
CGPointMake(160, 0),
CGPointMake(160, 568),
UInt32(kCGGradientDrawsBeforeStartLocation) | UInt32(kCGGradientDrawsAfterEndLocation))
CGContextRestoreGState(context)
}
This Stack Overflow post might help, but I couldn't make sense of it.
Update
I am also getting the error for latitude
, longitude
, and navBarAttributesDictionary
:
func configureView() {
// Set table view's bakground property
tableView.backgroundView = BackgroundView()
// Change the size and font of nav bar text
if let navBarFont = UIFont(name: "HelveticaNeue-Thin", size: 20.0) {
let navBarAttributesDictionary: [String: AnyObject]? = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: navBarFont]
}
navigationController?.navigationBar.titleTextAttributes = navBarAttributesDictionary
} ^ ================ Error Here
And:
let forecastService = ForecastService(APIKey: forecastAPIKey)
forecastService.getForecast(latitude, long: longitude) {
(let currently) in ^ =========== ^ ================ Error Here
if let currentWeather = currently {
dispatch_async(dispatch_get_main_queue()) {
if let temperature = currentWeather.temperature {
self.currentTemperatureLabel?.text = "\(temperature)ΒΊ"
}
if let precipitation = currentWeather.predipProbability {
self.currentPrecipitationLabel?.text = "Rain: \(precipitation)%"
}
if let icon = currentWeather.icon {
self.currentWeatherIcon?.image = icon
}
self.locationLabel.text = "\(self.location)"
}
}
}
}
Pasan Premaratne
Treehouse TeacherOk gimme a bit of time to investigate. Currently publishing a course and then I'll get to it!
Caleb Kleveter
Treehouse Moderator 37,862 PointsSwift 2.0 Functions? Just got the announcement, and am exited to start!
1 Answer
Pasan Premaratne
Treehouse TeacherReplace this line of code
UInt32(kCGGradientDrawsBeforeStartLocation) | UInt32(kCGGradientDrawsAfterEndLocation))
CGContextRestoreGState(context)
with this
[.DrawsBeforeStartLocation, .DrawsAfterEndLocation])
Swift 2 introduces a new Option Set Type that changes the syntax.
For the second error, change this line of code
let navBarAttributesDictionary: [NSObject: AnyObject]?
to this
let navBarAttributesDictionary: [String: AnyObject]?
In Swift 1.2 the API required setting the type of the dictionary as [NSObject:AnyObject]. This has been changed to [String: AnyObject].
Caleb Kleveter
Treehouse Moderator 37,862 PointsThanks for the help! The first code block got changed successfully. As for the second one I already had the alternate code.
And do you know what to do about this line?
forecastService.getForecast(latitude, long: longitude)
I am getting the 'Use of unresolved identifier' error for latitude and longitude.
Pasan Premaratne
Treehouse TeacherI'm not getting that :/ I downloaded the project files attached to this video and ran the automatic Swift converter. Did you perhaps make a change? I think it should be coordinate.lat
and coordinate.long
at this point in the code
Caleb Kleveter
Treehouse Moderator 37,862 PointsThat did it! And to fix the issue with the navBarAttributesDictionary
, I used the '!' instead of the if statement.
Pasan Premaratne
Treehouse TeacherPasan Premaratne
Treehouse TeacherUsing Swift 2?