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

THCrystalBall class issue

My understanding is that the point of creating this class is to create a better/efficient way to choose a random quote, and so that I can use this class for other things. I got the main part of the assignment to work, but I wanted to take the random text color extra credit a step further and include that in this class for practice.

The code that was successful for the random quote was:

    - (NSString *)randomPrediction {
        int random = arc4random_uniform(self.predictions.count);
        return [self.predictions objectAtIndex:random];
    }

I followed the exact same steps for the random text color and I believe the error in my code is here:

    - (NSString *)randomColor {
        int random = arc4random_uniform(self.colors.count);
        return [self.colors objectAtIndex:random];
    }

This accesses an array I have that looks like this:

    - (NSArray *) colors {
        if (_colors == nil) {
            _colors = [[NSArray alloc] initWithObjects:
                       [UIColor redColor],
                       [UIColor blackColor],
                       [UIColor blueColor], nil];
        }
        return _colors;
    }

The Warning (NOT error) I'm getting is: Incompatible pointer types assigning to 'UIColor *' from 'NSString *' Does my random color code need to return something other than an NSString? My code still works but I don't want the warning to be there.

2 Answers

Your randomColor method returns a NSString when it should return a UIColor. Unlike the predictions array, which is filled with NSString objects, your colors array is filled with UIColor objects.

Perfect. Thank you!

This helped me track down a similar problem I was having.

  • (NSString *)randomColor { should be
  • (UIColor *)randomColor {