0

I've got a class, called Letter. In the init method of Letter I am trying to load an Array of strings, so they can be used by other methods of that class.

I'm then instantiating an object based on the Letter class. I am expecting the init call to load the array, but instead am getting a EXC_BAD_ACCESS error.

Letter.h

@interface Letter : NSObject
{
    NSArray *consonants;
}

-(BOOL)typeOfLetter:(NSString *)_letter; 

Letter.m

#import "Letter.h"

@implementation Letter

- (id)init {
    self = [super init];
    if (self) {
        consonants = [NSArray arrayWithObjects:@"B",@"C",@"D",@"F",@"G",@"Ğ",@"H",@"J",@"K",@"L",@"M",@"N",@"P",@"R",@"S",@"Ş",@"T","@U",@"V",@"Y",@"Z",@"b",@"c",@"d",@"f",@"g",@"ğ",@"h",@"j",@"k",@"l",@"m",@"n",@"p",@"r",@"s",@"ş",@"t",@"u",@"v",@"z",nil];        
    }
    return self;
}

ViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    BOOL retValue;

    Letter *letter = [[Letter alloc] init];
    retValue = [letter typeOfLetter:@"a"];

}

What am I doing incorrectly here?

3
  • are you using ARC? does it crash here "[[Letter alloc] init]"? Commented Jun 10, 2012 at 12:12
  • If he used ARC it would throw a proper NSException instead of simply segfaulting. Commented Jun 10, 2012 at 12:15
  • I thought I selected ARC when creating the project. The compiler is the Apple LLVM Compiler 3.1. That makes it ARC, doesn't it? Commented Jun 10, 2012 at 12:21

1 Answer 1

3

You have forgotten to add a @ before one of your strings In your array you have this character "@U" you will have to change it to @"U"

Sign up to request clarification or add additional context in comments.

2 Comments

Brilliant! Thanks mate. I'll have to look more carefully at those long lists of strings next time,
Thanks mate! That was it. I'll have to look at those long lists of strings more carefully in future. Cheers.

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.