预期的标识符'('in Xcode

问题描述:

我对这个第一行代码有问题,它说有一个“期望的标识符”(''不确定它是否与UIApplication有关, VE已经宣布的UIApplication为一类。有人请帮助我这个预期的标识符'('in Xcode

@interface UIResponder : NSObject 

    @end 


    Class UIApplication; UIResponder 




    // Error in the line below 
    - (void)applicationDidBecomeActive:(UIApplication *) application { 

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://foobar.com/news.plist"]]; 
request.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData; 
request.timeoutInterval = 5.0; 

[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler: 
^(NSURLResponse *response, NSData *data, NSError *error) 
{ 
    if (data) 
    { 
     NSPropertyListFormat format; 

     self.dictionary = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:nil]; 

     // Todo: post an NSNotification to any other view controllers telling them that we have the new data. 

    } 
    else 
    { 
     // Tell user connection failed 
    } 
}]; 

}

+0

语法错误取决于这些代码放在哪里,如果你遇到错误第一行,之前的界限很重要。显示导致错误的行之前的所有行。 – OOPer

+0

刚刚编辑该问题以显示代码的前几行 – TheFrontier

+0

您的代码完全被破坏为Objective-C类定义。尝试在Objective-C中创建一个新的单视图应用程序,并查看Objective-C中的AppDelegate如何。在Objective-C中,类定义不使用'Class'关键字。你通常不会重新声明'UIApplication'。你是否学过关于ObjC编程的基础知识? – OOPer

你需要把“}]”在这样的结尾。

[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler: 
^(NSURLResponse *response, NSData *data, NSError *error) 
{ 
    if (data) 
    { 
     NSPropertyListFormat format; 

     self.dictionary = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:nil]; 

     // Todo: post an NSNotification to any other view controllers telling them that we have the new data. 

    } 
}];