0

Im getting the following error:

on the line self = [super init];

cannot assign self outside method init family

also getting yellow triangles on all self.whatever = whatever;

local declaration of "whatever" hides instance variable

@synthesize firstName, lastName, emailAdress, password, admin;

//current course funkade med nil men inte @"" vrf ;P
-(id) init
{
    return [self initwithName:@"" lastName:@"" password:@"" admin:@"" currentCourse:nil];
}

-(id) initwithName:(NSString *) firstName
          lastName:(NSString *) lastName
          password:(NSString *) password
             admin:(NSString *) admin
     currentCourse:(NSDictionary *) course
{
    self = [super init];
    if (self) {
        self.firstName = firstName;
        self.lastName = lastName;
        self.password = password;
        self.admin = admin;

    }
    return self;
}

2 Answers2

2

You have synthesized @synthesize firstName, lastName, emailAdress, password, admin;

And in your method you are using same name

-(id) initwithName:(NSString *) firstName
          lastName:(NSString *) lastName
          password:(NSString *) password
             admin:(NSString *) admin
     currentCourse:(NSDictionary *) course

Change these to something else or remove synthesize, if your compiler supports auto-synthesize

-(id) initWithName:(NSString *) aFirstName
          lastName:(NSString *) aLastName
          password:(NSString *) aPassword
             admin:(NSString *) aAdmin
     currentCourse:(NSDictionary *) aCourse
{
    self = [super init];
    if (self) {
        self.firstName = aFirstName;
        self.lastName = aLastName;
        self.password = aPassword;
        self.admin = aAdmin;

    }
    return self;
}
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
1

Anoop has nailed the properties stuff, but your first problem remains unanswered.

My first post was " I think that the reason you can't assign to self is that you're method signature for init is not correct.

I'm not 100% sure of this, but I think that for an implementation of X, init should return (X*) " which is bogus - (id) init; is completely valid.

The error message doesn't feel completely accurate for the following, but amongst your problems is that in - (id) init, you call [self initWith....], but at this point, self has not been set. If you want to write that code once, you'll have to refactor, but the better solution, IMHO, is

- (id) init {
    self = [super init];
    if ( self) {
        self.firstName = @"";
        self.lastName = @"";
        self.password = @"";
        self.admin = @"";
    }
    return self;
}

For a bonus point, I'd also like to point out that you don't use/set course :)

Gordon Dove
  • 2,537
  • 1
  • 22
  • 23
  • @anoop, I know this, I'm trying to explain the first error, but stand by for an updated answer, as I now see the problem :) – Gordon Dove Apr 26 '13 at 00:09