Have a few errors in my code which I have commented out but don’t know how to fix. Can you please take a look and tell me what I need to do to fix it?
TIA
Implementation file
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize textField;
@synthesize label;
@synthesize userName = _userName;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setTextField:nil];
[self setLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)changeGreeting:(id)sender {
self.userName = self.textField.text;
NSString *nameString = self.userName;
if ([nameString length] == 0)
nameString = @"World";
}
NSString *greeting = [[NSString alloc]initWithFormat:@"Hello, %@!", nameString]; // Use of undeclared identifier 'nameString'
self.label.text = greeting; // Unknown type 'self'
} // Expected external declaration
@end
Interface file:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UILabel *label;
- (IBAction)changeGreeting:(id)sender;
@property (copy, nonatomic)NSString *userName;
@end
The last if block in the first file doesn’t have an opening bracket