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

Making a simple iPhone app with Swift - Changing background color

Hi, I am stumped; I have copied the code verbatim but I am getting a red error message on the bottom of the page. Can anyone help?

import Foundation
import UIKit

struct ColorWheel {
    let colorsArray = [
        UIColor(red: 90/255.0, green: 187/255.0, blue: 181/255.0, alpha: 1.0), //teal color
        UIColor(red: 222/255.0, green: 171/255.0, blue: 66/255.0, alpha: 1.0), //yellow color
        UIColor(red: 223/255.0, green: 86/255.0, blue: 94/255.0, alpha: 1.0), //red color
        UIColor(red: 239/255.0, green: 130/255.0, blue: 100/255.0, alpha: 1.0), //orange color
        UIColor(red: 77/255.0, green: 75/255.0, blue: 82/255.0, alpha: 1.0), //dark color
        UIColor(red: 105/255.0, green: 94/255.0, blue: 133/255.0, alpha: 1.0), //purple color
        UIColor(red: 85/255.0, green: 176/255.0, blue: 112/255.0, alpha: 1.0), //green color
    ]
    func randomColor() -> UIColor {
        var unsignedArrayCount = UInt32(colorsArray.count)
        var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
        var randomNumber = Int (unsignedRandomNumber)

        return colorsArray[randomNumber]
}

3 Answers

What does the error say?

At first sight I think this code needs an extra } at the end.

It says : Swift compiler error: Expected declaration ColorWheel swift. Adding the other bracket made the red dot go away but messed up the code in the simulator so that it no longer worked.

Thank you for the suggestion though. Any other ideas Vittorio?

Hi Vittorio, When I do that (Add a brace) the red dots go away and a green line appears across the "return" line saying Thread 1: breakpoint 2.1 at the extreme right. Any clues?

Pasan Premaratne
Pasan Premaratne
Treehouse Teacher

Jason Larkin,

This means you have a breakpoint enabled. A break point looks like this and should be visible somewhere in your standard editor. Breakpoints stop the execution of your code at the point specified so when you hit the breakpoint in your code, the simulator pauses so you can debug things.

If you can't find the breakpoint in your standard editor, it's also available in the breakpoint navigator (shortcut key: command + 7) and it should be listed there. Right click and select delete to get rid of it.

Could not have said it better Pasan Premaratne !!

:D

All sorted Jason Larkin ?

Thanks to both of you gentlemen- your suggestions finally solved it!