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

Swift FunFacts Help!

I downloaded the project files for the FunFact app to make to compare to my ColorWheel.swift file, because I was getting this error 'UIColor' is not a subtype of NSString' but its still showing the error in the teachers code, please help I'm stuck! :(

6 Answers

Stone Preston
Stone Preston
42,016 Points

you have a function nested inside your randomColor function

func randomColor() -> UIColor {
        func randomFact() -> String {
            var unsignedArrayCount = UInt32(colorsArray.count)
            var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
            var randomNumber = Int(unsignedRandomNumber)

        return colorsArray[randomNumber]
    }
}

remove the nested function heading and brackets

func randomColor() -> UIColor {

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

        return colorsArray[randomNumber]

}

return colorsArray[randomNumber] ------ !!!'UIColor' is not a subtype of 'NSString'

Downloaded teachers code and still have an Error

Stone Preston
Stone Preston
42,016 Points

check the return type of your function. make sure its returning UIColor and not String. Also can you paste in the full function

func randomColor() -> UIColor { func randomFact() -> String { var unsignedArrayCount = UInt32(colorsArray.count) var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount) var randomNumber = Int(unsignedRandomNumber)

    return colorsArray[randomNumber]
}

}

Thank you, I accidentally copy and pasted that extra function. Oops.