在Objective C中调用类init时的EXC_BAD_ACCESS

net*_*age 2 iphone objective-c

我一直试图解决这个问题,但我无法弄清楚我做错了什么.

我写了一个类,每当我尝试初始化它时,我都会收到EXC_BAD_ACCESS错误.我甚至无法进入初始化.

任何人都知道我做错了什么?

User *myUser = [myUser init];
Run Code Online (Sandbox Code Playgroud)

.h文件:

#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
Run Code Online (Sandbox Code Playgroud)

.m文件

#import "User.h"


@implementation User

@synthesize rowId, email, password, fileVersion;

-(id)init {

    self = [super init];
    return self;
}

@end
Run Code Online (Sandbox Code Playgroud)

Dav*_*ong 11

你必须实际分配对象:

User *myUser = [[User alloc] init];
Run Code Online (Sandbox Code Playgroud)

release当你使用它时不要忘记它.