开发者

Error while attempting to output data onto console in xcode

I am trying to output general data (source code) from a website, but it just sits there. Can't figure out if its the interface or the code. Would someone double-check for me?

 #import "Lockerz_RedemptionViewController.h"

@implementation Lockerz_RedemptionViewController
-(IBAction)start: (id) sender {
 while (1) {


  NSMutableData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://ptzplace.lockerz.com/"]];

  NSString *output = [[开发者_运维技巧NSString alloc] initWithData:mydata encoding:NSASCIIStringEncoding];
  NSLog(output);


 }
}


The reason your NSLog doesn't work is it should use format strings.

Replace:

NSLog(output);

With:

NSLog(@"%@",output);

For more info see http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html


Why the while(1)? Are you intentionally trying to set up an infinite loop? You should just run this once, or maybe set up a periodic timer to reload it every few seconds, but certainly don't use an infinite loop for that... also it's been a while since I did anything with Cocoa networking, but you might want to look into NSURLRequest. You also may want to try NSData's dataWithContentsOfURL:options:error: and check the error parameter to better see what might be going wrong. Hope this helps you out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜