James Plen James Plen - 6 months ago 14
iOS Question

ViewController UIwebview issue

I am new to xcode so I was following a tutorial about putting a webpage into an ios objective-c project in xcode 7. Below is the code I use.
@interface ViewController ()

View controller header

@interface ViewController : UIViewController

IBOutlet UIWebView* webView;

@property (nonatomic, retain) UIWebView *webView;

@end

view controller main
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@synthesize webView;

@end


The bug warnings are;

1.Cannot declare variable inside @interface or @protocol'

2.Attribute can only be applied to instance variables or properties

And both apply to the first line starting with IBOutlet

Answer

for instance variables Just missing {}

@interface ViewController : UIViewController
{
  IBOutlet UIWebView* webView;
}
@property (nonatomic, retain) UIWebView *webView;

@end

but actually the declaration can be skipped eg.

@interface ViewController : UIViewController

@property (nonatomic, retain) IBOutlet UIWebView *webView;

@end

This line

@synthesize webView;

should put below @implementation for consistency, and can skip as well

(after Xcode 4.4 the compiler will generate for u, but it's good to know the original code)

more about class: https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/ClassMethod.html