编译while循环期望标识符时出现错误消息

时间:2010-05-29 00:48:04

标签: xcode while-loop

当尝试在基于xcode iphone视图的应用程序中编译无限循环时,它给出了一个错误,它读取了预期的标识符或'(''while'之前'。我使它尽可能简单。抱歉图片。代码阻止无效。如果你想看到代码的图像,这里是链接。http://www.freeimagehosting.net/uploads/931d5d8788.gif

#import "Lockerz_NotifierViewController.h"

@implementation Lockerz_NotifierViewController
NSMutableData *responseData;

while (1) {
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://amicionline.me"]
                                                cachePolicy:NSURLRequestUseProtocolCachePolicy
                                            timeoutInterval:60.0];
    // create a connection
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if(theConnection) {
        // create the datum
        responseData=[[NSMutableData data] retain];
    } else {
        // code this later
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [responseData setLength:0];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // make it work
    NSLog(@"Succeeded! Received %d bytes of data:",[responseData length]);

    // release it
    [connection release];
    [responseData release];

}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

1 个答案:

答案 0 :(得分:0)

你想做什么?您不能直接在@implementation中编写代码。您必须将其放在方法中,例如:

-(void)start {
   while (1) {
     ...
   }
}