1

I'm having a problem with this the first line of code, it says that there is an "expected identifier '('" Not sure if it has something to do with UIApplication. I've already declared UIApplication as a class. Someone please help me with this

    @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
     }
 }];

}

  • Syntax errors depends on where those code is put. If you get error at the first line, the lines before it is important. Show all lines before the line causing the error. – OOPer Aug 07 '17 at 03:09
  • Just edited the question to reveal the previous lines of code – TheFrontier Aug 07 '17 at 03:15
  • Your code is completely broken as an Objective-C class definition. Try creating a new Single View App in Objective-C and see how AppDelegate in Objective-C looks like. In Objective-C, class definition does not use `Class` keyword. And you usually do not redeclare `UIApplication`. Have you learned basics about ObjC programming? – OOPer Aug 07 '17 at 03:29
  • No, I need to find a way that'll update my app overtime you scroll up like a news app. How do you do that in Swift? – TheFrontier Aug 07 '17 at 11:14
  • The single line description is not clear enough to show something. And what you say here is completely different than your question, the code you have shown has nothing to do with _scroll up_ things. I recommend you to close or delete this thread and start a new thread with clarified explanation about what you really want to do. One more, if you prefer Swift, find a code snippet written in Swift. – OOPer Aug 07 '17 at 11:27

1 Answers1

1

You need to put "}]" at the end like this.

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

     }
}];
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56