My app is simple. It reads the stock symbol (AAPL) from Yahoo Finance and gets the price. Every half of a second it refreshes the stock price. Sometimes it crashes, can anyone help explain this to me, as to why it crashes. I get the error "unable to parse"
#import "ViewController.h"
#import "TFHpple.h"
@interface ViewController ()
@property UILabel *stockStymbol;
@property UILabel *stockPrice;
@end
//@"http://finance.yahoo.com/q?s=AAPL"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_stockStymbol = [[UILabel alloc]init];
_stockPrice = [[UILabel alloc]init];
[self parseStockSymbol];
[NSTimer scheduledTimerWithTimeInterval:0.5f
target:self
selector:@selector(parseStockSymbol)
userInfo:nil repeats:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) parseStockSymbol
{
NSURL* baseURL = [NSURL URLWithString:@"http://finance.yahoo.com/q?s=AAPL"];
NSData *data = [[NSData alloc]initWithContentsOfURL:baseURL];
TFHpple *xpathParser = [[TFHpple alloc]initWithHTMLData:data];
NSArray *elements = [xpathParser searchWithXPathQuery:@"//span[@class='time_rtq_ticker']"];
TFHppleElement *element = [elements objectAtIndex:0];
_stockStymbol.text = @"AAPL";
[_stockStymbol sizeToFit];
_stockPrice.text = [[element firstChild]content];
[_stockPrice sizeToFit];
_stockPrice.frame = CGRectMake(100, 30, _stockPrice.bounds.size.width, _stockPrice.bounds.size.height);
_stockStymbol.frame = CGRectMake(30, 30, _stockStymbol.bounds.size.width, _stockStymbol.bounds.size.height);
[self.view addSubview:_stockStymbol];
[self.view addSubview:_stockPrice];
}
@end
Aucun commentaire:
Enregistrer un commentaire