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

iOS Enhance a Weather App with Table Views Upgrading Stormy Custom Background Views

Drawing Code for Linear Gradient isn't working

I'm using Xcode 7 for this course, so I found that part of my code wouldn't compile. This is the drawing code for a linear gradient which provided for both Xcode 6 and 7. I tried both. The snippet for Xcode 6 gave a compiler error for the constants kCGGradientDrawsBeforeStartLocation and kCGGradientDrawsAfterEndLocation. The Xcode 7 snippet, contained in a project download, compiled, but no gradient appeared in the WeeklyTableViewController. HEEEEEEEEELLLP!!!

4 Answers

Nathan Tallack
Nathan Tallack
22,160 Points

For some reason the constants are not available to the function. No idea why.

I managed to get it working by calling it with the built in option flag. Unfortunatly it seems you can only call either drawsbefore or drawsafter, looks like you cant call both. Looks ok just calling drawsafter though.

So, replace the line

UInt32(kCGGradientDrawsBeforeStartLocation) | UInt32(kCGGradientDrawsAfterEndLocation))

with

CGGradientDrawingOptions.DrawsAfterEndLocation)

Giedrius Zavadskas
Giedrius Zavadskas
6,427 Points

HI

Replace this: UInt32(kCGGradientDrawsBeforeStartLocation) | UInt32(kCGGradientDrawsAfterEndLocation))

with this: [.DrawsAfterEndLocation, .DrawsBeforeStartLocation])

Tommy Choe
Tommy Choe
38,156 Points

Hey all, just wanted to let you know that Pasan answered this question on this forum post: https://teamtreehouse.com/community/use-of-unresolved-identifier-kcggradientdrawsbeforestartlocation

He explains why its not working.

Hope that helps.

@ Nathan Tallack : It worked on Xcode 7. Thanks for ur help.