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 trialDmitry Pavlovsky
2,502 PointsDifferente ways?
Why should we declare new constant randomColor in ViewController? while view.backgroundColor = colorProvider.randomColor() where randomColor is taken from BackgroundcolorProvider will works as well.
1 Answer
Anthony Attard
43,915 PointsIt's a personal choice. One could argue the 2 line method is more clear on what's going on instead of having one long line.
Edit: In this case it makes sense to store the color in a constant since we are assigning the same color on 2 elements, the background and the button tint/text color. Otherwise the 2 elements would have different colors and would not be correct.