Reputation: 1472
I have made a very basic iOS app which displays the time in a label on viewDidLoad. I'm getting an Expected Identifier error on this line of code :
NSString *myTime = [myDateFormatter stringFromDate:[*myDate]];
Here'e the ViewController.m file :
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize timeLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init];
[myDateFormatter setDateFormat:@"HH:mm a"];
NSDate *myDate = [[NSDate alloc] init];
NSString *myTime = [myDateFormatter stringFromDate:myDate];
[timeLabel setText : myTime];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Made some additions. The code compiled but now I'm getting a Thread 1:SIGABRT error. The application doesn't load on the Simulator and the error comes. Here's the line of code which is giving the error in the main() :
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
Yup, I didn't link it. Its working now. Thank you all!
Upvotes: 2
Views: 7011
Reputation: 6302
I'm with SKM17 NSString *myTime = [myDateFormatter stringFromDate:mydate];
but just make sure there is something in mydate with
NSLog("mydate = %@",mydate);
if it still doesn't appear. Logging is always a good idea to check that values are where they are supposed to be :D
Upvotes: 0
Reputation: 1742
SIGABRT error occurs when an exception is encountered while the application is run. This may be due to a memory exception or any other runtime error.
You can try to clean and build you project. If it persists, check the target debugger console .
Upvotes: 0
Reputation: 723
Try this : NSString *myTime = [myDateFormatter stringFromDate:myDate];
Upvotes: 0
Reputation: 3259
remove * like this
NSString *myTime = [myDateFormatter stringFromDate:mydate];
Upvotes: 8
Reputation: 4856
Try this NSString *myTime = [myDateFormatter stringFromDate:[NSDate date]];
Upvotes: 0