0

I am trying to debug an issue related to an NSArray. I am getting an exception:

EXC_BAD_ACCESS(code=EXC_1386_GPFLT) at this line:

NSArray *items = [[NSArray alloc] initWithObjects:@"A", "B", "C", nil];

This code is inside -(id)initWithFrame:(NSRect)frame inside an NSView.

What is causing me to get this exception? I've Google-d the exception and I haven't found anyone else who gets it.

This project is for OS X and not iOS.

1 Answer 1

5

The first argument you're passing to initWithObjects: is an object (it's an instance of NSString), but the next two are not. It's illegal to insert non-object types into an Objective-C collection.

You need to prefix all of the string literals with @ symbols to make them all objects, as shown below:

NSArray *items = [[NSArray alloc] initWithObjects:@"A", @"B", @"C", nil];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.