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 trialAustin 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.