Skip to content

Instantly share code, notes, and snippets.

@joseph-montanez
Created September 9, 2013 04:19
Show Gist options
  • Save joseph-montanez/6491416 to your computer and use it in GitHub Desktop.
Save joseph-montanez/6491416 to your computer and use it in GitHub Desktop.
Accessing thenDate Crashes... 'NSInvalidArgumentException', reason: '-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x7659160'
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (nonatomic) NSDate* thenDate;
@property (nonatomic) NSDate* nowDate;
@property (retain, nonatomic) IBOutlet UILabel *theTimer;
@property (retain, nonatomic) IBOutlet UILabel *theLabel;
-(void) updateTimer:(id) sender;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize theLabel;
@synthesize theTimer;
@synthesize thenDate;
@synthesize nowDate;
-(void)updateTimer:(id)sender{
nowDate = [NSDate date];
NSTimeInterval startTime = [nowDate timeIntervalSinceReferenceDate];
NSTimeInterval endTime = [thenDate timeIntervalSinceReferenceDate];
}
- (void)viewDidLoad
{
[super viewDidLoad];
thenDate = [NSDate date];
nowDate = [NSDate date];
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
theLabel.text = @"Time";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[theLabel release];
[theTimer release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment