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.

Austin Rau
Courses Plus Student 3,214 PointsSwift 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
42,016 Pointsyou 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]
}

Austin Rau
Courses Plus Student 3,214 Pointsreturn colorsArray[randomNumber] ------ !!!'UIColor' is not a subtype of 'NSString'

Austin Rau
Courses Plus Student 3,214 PointsDownloaded teachers code and still have an Error

Stone Preston
42,016 Pointscheck the return type of your function. make sure its returning UIColor and not String. Also can you paste in the full function

Austin Rau
Courses Plus Student 3,214 Pointsfunc randomColor() -> UIColor { func randomFact() -> String { var unsignedArrayCount = UInt32(colorsArray.count) var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount) var randomNumber = Int(unsignedRandomNumber)
return colorsArray[randomNumber]
}
}

Austin Rau
Courses Plus Student 3,214 PointsThank you, I accidentally copy and pasted that extra function. Oops.