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

Paul Denlinger
Paul Denlinger
2,380 Points

"UIColor is not convertible to ()" error; cannot compile

Am getting two compilation errors with my code; they both say "UIColor is not convertible to ()" and won't let me compile.

Get one error on the

return colorsArray[randomNumber]

line in ColorWheel.swift, and the other error is on the showFunFact() method in the view controller:

@IBAction func showFunFact() {
        var randomColor = colorWheel.randomColor()
        view.backgroundColor = colorWheel.randomColor
        funFactButton.tintColor = colorWheel.randomColor
        funFactLabel.text = factBook.randomFact()
    }

What is wrong?

6 Answers

Sorry for the delay, I'd gone out for a bit. Friday night & pub etc! I tried to answer your query on my phone but there's rubbish reception here in deepest, darkest Norfolk.

I think the issue you now have is that you have missed the parentheses from your method calls.

randomColor(); // brackets missing in your code

Sorry I didn't pick this up in your first post.

Steve.

Paul Denlinger
Paul Denlinger
2,380 Points

Hi Steve, That resolved the issue; thank you!

Hi Paul,

Can you post the code for the randomColor method inside the ColorWheel class please?

It looks as though the method is returning a color instance but the method skeleton doesn't say it will do that. Just guessing at the moment until I can have a look at the code.

Post it all, if you want.

Steve.

Paul Denlinger
Paul Denlinger
2,380 Points

Here you go:

func randomColor() {
        var unsignedArrayCount = UInt32(colorsArray.count)
        var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
        var randomNumber = Int(unsignedRandomNumber)

        return colorsArray[randomNumber]
    }
```swift

Yes - your func doesn't return anything in it's definition but then does in the method body.

You need to add -> UIColor in the header like:

func randomColor() -> UIColor {

Hope that works!!

Steve.

Paul Denlinger
Paul Denlinger
2,380 Points

Hi, thank you. I have added UIColor to the method signature for the randomColor method, but am still getting the same error for the showFunFact() method on lines 3, 4:

@IBAction func showFunFact() {
        var randomColor = colorWheel.randomColor()
        view.backgroundColor = colorWheel.randomColor
        funFactButton.tintColor = colorWheel.randomColor
        funFactLabel.text = factBook.randomFact()
    }
```swift
Anthony Walker
Anthony Walker
4,448 Points

Has this question been answered as I too have the error. Everything works fine until the variable randomColor is created.

Removing the curly brackets to colorWheel. randomColor on both view.backgroundColor and funFactBytton.tintColor gives the error

function produces expected UIColor, did you mean to call it with '()'?

Hi Anthony,

I don't know what problem you're facing.

For starters, don't remove the brackets - they are essential for the methods you mention. ]

If you could post your code and let me know what errors you're getting, I'll have a look through and see if I can help you out.

Steve.

Anthony Walker
Anthony Walker
4,448 Points

Its ok I have code working. For the code above remove colorWheel from view.backgroundColor = colorWheel.randomColor and factFunButton.tintColor = colorWheel.randomColor

both these codes should read

view.backgroundColor = randomColor funFactButton.tintColor = randomColor

Why?

Because var randomColor is replacing all off colorWheel.randomColor()