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 Build a Simple iPhone App (iOS7) Refactoring into a Model Readonly Attribute

Marlon Pleitez
seal-mask
.a{fill-rule:evenodd;}techdegree
Marlon Pleitez
Full Stack JavaScript Techdegree Student 9,563 Points

Making a method to return NSColor?

Hi guys right now I'm following the track and I am at the part where we moved the predictions from the controller to the model. I got everything working but I am also following the extra credit which instructs you to change the color of the prediction as well. I got it working in the controller file but when I created a method for randomColors (just like we did for randomPrediction), I get an error and I don't know how to solve it. This is my method in the h file.

-(NSColor *) randomColor;

What I'm asking is what goes in the return type? Because I know NSColor * is not it. Thanks!

3 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

If your trying to make a method that returns a random color you method declaration is correct

EDIT the method would look something like this:

-(UIColor *)randomColor
{
    float red = arc4random() % 255 / 255.0;
    float green = arc4random() % 255 / 255.0;
    float blue = arc4random() % 255 / 255.0;
    UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];

    return color;
}
Marlon Pleitez
seal-mask
.a{fill-rule:evenodd;}techdegree
Marlon Pleitez
Full Stack JavaScript Techdegree Student 9,563 Points

I am trying to return a random color but the compiler keeps coming up with the error 'expected a type'.

EDIT: I just figured it out, I was trying to return an NSColor when it should have been UIColor! Syntax will always be the death of me. Thanks!

Thomas Nilsen
Thomas Nilsen
14,957 Points

I acutally didn't see that. Oh well, glad it worked out! :)