Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

ronald greti
ronald greti
800 Points

Adding a Pop of Color - Cannot invoke 'colorsArray' with an argument of type '(Int)'

I am following your course in the tutorial Adding a Pop of Color wherein I am following your instructions to add the following line…

             return colorsArray(randomIndex)

but Xcode flags this as an error? ...

             Cannot invoke colorsArray with an argument of type (Int)

Can you help?

//
//  ColorWheel.swift
//  FunFacts
//
//  Created by ronald greti on 3/28/15.
//  Copyright (c) 2015 Treehouse. All rights reserved.
//

import Foundation
import UIKit

struct ColorWheel {

    //------------------------------------------------------------------------------------------------------
    // stored propeties...
    //------------------------------------------------------------------------------------------------------

    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
    ]

    //------------------------------------------------------------------------------------------------------
    // methods...
    //------------------------------------------------------------------------------------------------------

    func randomColor() -> UIColor {

        var unsignedArrayCount = UInt32(colorsArray.count)
        var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
        var randomIndex = Int(unsignedRandomNumber)

        return colorsArray(randomIndex)
    }
}

2 Answers

Hi Ronald,

I think you need to use square brackets to access the item at a position in an array.

So, return colorsArray[randomIndex] should work OK.

Give that a whirl and let me know if it works!

Steve.

ronald greti
ronald greti
800 Points

Oops! you are right, it was just a question of using [] instead of (). I missed that. The msg from Xcode was too cryptic for me to get that. Thanks for answering such a trivial mistake.

Yeah - the error messages are pretty obscure at times!

Glad it worked!

Steve.