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 Build a Simple iPhone App with Swift Improving Our User Interface Adding a Pop of Color

ColorWheel error

Seems like my ColorWheel struct metode expects a parameter event though its:

func randomColor() -> UIColor{ var randomNumber = Int(arc4random_uniform(UInt32(colorsArray.count))) return colorsArray[randomNumber] }

When im trying to change the background color with: view.backgroundColor = ColorWheel.randomColor()

i get the error "Missing arguments for parameter #1 in call"

whats wrong?

EDIT

It was "view.backgroundColor = ColorWheel().randomColor()" with a () efter ColorWheel ref: http://stackoverflow.com/questions/25435928/missing-argument-for-parameter-1-in-call-error-for-function-with-no-params-swi

2 Answers

Joseph Kandi
Joseph Kandi
2,640 Points

You are not using the variable from the struct, instead you are calling the method on the struct itself.

var colorWheel = ColorWheel()

Then later in the method you should use the variable when changing the color.

self.view.backgroundColor = colorWheel.randomColor()

This is the correct code:

let colorWheel = ColorWheel()
// Just as Pasan wrote. Random color and random number use same code.
// Remember it's capital 'C' for Color which means it's the method not the variable.

view.backgroundColor = colorWheel.randomColor()
// Just as Pasan wrote. You don't need to write 'self.'.

I'm not sure why he didn't get any errors though.