2

I've been trying to figure this out but I can't figure out what I'm doing wrong.

I wrote a class and whenever I try to initialize it, I get a EXC_BAD_ACCESS error. I can't even step into the initialization.

Anyone have any idea what I'm doing wrong?

User *myUser = [myUser init];

.h file:

#import <Foundation/Foundation.h>


@interface User : NSObject {
    long rowId;
    NSString *email;
    NSString *password;
    NSString *fileVersion;
}

@property long rowId;
@property (assign) NSString *email;
@property (assign) NSString *password;
@property (assign) NSString *fileVersion;

@end

.m file

#import "User.h"


@implementation User

@synthesize rowId, email, password, fileVersion;

-(id)init {

    self = [super init];
    return self;
}

@end
1
  • 2
    Be sure to understand what’s an assign property and why it’s not common for NSString* properties to be assign (hint: they’re usually copy). Commented Jan 19, 2011 at 23:06

1 Answer 1

11

You have to actually allocate the object:

User *myUser = [[User alloc] init];

Don't forget to release it when you're done using it.

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

2 Comments

Or autorelease it upon allocation (in which case, it's usual to write a helper class method that does the alloc/init/autorelease).
Thanks, I was hoping it was something obvious.

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.