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

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.