iphone - objective c class instance declaration error? -


i very new objective-c , im trying declare new instance of uitableview in xcode. here code:

uitableview *maintable = [[uitableview alloc] init]; 

and xcode pointing @ = , bothering me semicolon @ end of declaration statement, there.

edit:

#import <uikit/uikit.h>  @interface testrunappdelegate : nsobject <uiapplicationdelegate> {      uitableview *maintable = [[uitableview alloc] init];  } 

you can't make assignments inside class's interface.

move assigment app delegate's init method:

#import <uikit/uikit.h>  @interface testrunappdelegate : nsobject <uiapplicationdelegate> {      uitableview *maintable;  } @end  @implementation testrunappdelegate  - (id)init {      if( !(self = [super init]) ){         return nil;      maintable = [[uitableview alloc] init];      return self; } @end 

the @interface block (everything @interface @end) tells other code expect class. doesn't do itself. between curly braces, declare instance variables, don't create objects. after instance variable declaration , before @end, declare methods. again, don't implement them. you're letting compiler, , other code imports header, know can expect class do.

the reason separating implementation , interface in way* realize 1 of tenets of object-oriented programming. object tells other objects can (the interface), makes no statement how accomplish task (implementation).


*they put 2 separate files don't have be.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -