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 trialSteve Dowd
1,745 PointsWhy is it neccessary for a contant to be created to use the function of ColorWheel?
Why must the function of ColorWheel be passed to a constant? Why does it not work if I try to call the Struct itself and use its function to assign a random color like ColorWheel.randomColor() instead of colorWheel.randomColor()?
1 Answer
Greg Kaleka
39,021 PointsHi Steve,
Without seeing the full struct, the answer is probably that randomColor()
is an instance method, not a type method. That means you need to create an instance of the struct in order to use its methods and properties. This is very typical behavior.
Check out this page in the Swift Language Guide for more information.
Good luck!