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!

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) Creating a Data Collection Implementing an Array

Jordan Lemmons
Jordan Lemmons
3,146 Points

Can you use literals to implement a localized array??

In the 'Objective-C Basics' section, we talked about the shorthand for implementing strings, arrays, numbers and dictionaries using the '@' compiler directive. I tried getting fancy and using this method for implementing the '*predictions' array and got an error.

Here's the code:

- (IBAction)buttonPressed {
    self.predictionLabel.textColor= [UIColor redColor];
    NSArray *predictions = @[
                            @"It is Certain",
                            @"It is Decidely So",
                            @"All signs say Yes",
                            @"The stars are not aligned",
                            @"The reply is no",
                            @"It is doubtful",
                            @"Better not tell you now",
                            @"Concentrate and ask again",
                            @"Unable to answer now", nil];
//And the error
! Collection element of type 'void' is not an Objective-C object

Any thoughts?

2 Answers

David Kaneshiro Jr.
David Kaneshiro Jr.
29,247 Points

Hi Jordan Lemmons

When using that version of the syntax it looks like you don't need the nil at the end of your array items list before the closing square brace.