2017-08-07 113 views
1

我對這個第一行代碼有問題,它說有一個「期望的標識符」(''不確定它是否與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

回答

1

你需要把「}]」在這樣的結尾。

[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. 

    } 
}];