开发者

I'm getting two errors having to do with incorrect Xcode grammar

开发者 https://www.devze.com 2023-04-02 17:47 出处:网络
(MemberPage *)initWithString: (NSString *) s{ self = [super init]; if ( self ) { 开发者_Go百科//DO STUFF;
(MemberPage *)initWithString: (NSString *) s  {
    self = [super init];

    if ( self ) {
 开发者_Go百科       //DO STUFF;
        UserNAME.text = s;
    }

}    
return self;

I'm getting: use of undeclared identifier initWithString expected ; before : token

I've haven't been able to fix this after an hour so far, Thanks


There are a few tweaks that will solve this. See comments inline:

// Add '-' to show it is instance method
-(MemberPage *)initWithString: (NSString *) s  {
    self = [super init];

    if ( self ) {
         //DO STUFF;
         UserNAME.text = s;
    }

    // Include this inside of the brace
    return self;
}    

As a note, by convention your instance variables should begin with a lower case letter and then use camel casing. So, UserNAME.text should be userName.text. The compiler expects this.


You are missing the - token before your method signature and the return statement is outside the method body. Should look like:

- (MemberPage *)initWithString: (NSString *) s  {
    self = [super init];

    if ( self ) {
        //DO STUFF;
        UserNAME.text = s;
    }

    return self;
}

You may also eventually have a problem on the UserNAME.text = s line but without seeing your header file its hard to tell.

0

精彩评论

暂无评论...
验证码 换一张
取 消