1

I see the following code:

@interface FViewController (UIWebViewDelegate) <UIWebViewDelegate>
@end

@implementation FViewController

@end


@implementation FViewController (UIWebViewDelegate)

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

}

.....

@end

Basically, FViewController is used to show a web view. What's the purpose of making it a category as the above?

Also what does this do:

@interface FViewController (UIWebViewDelegate) <UIWebViewDelegate>
Finn Larsen
  • 2,201
  • 17
  • 26
Kermit the Frog
  • 3,949
  • 7
  • 31
  • 39

2 Answers2

0

This doesn't make much sense to me. This code makes FViewController both implement the UIWebViewDelegate protocol, and create a category on it. The only possible reason for doing this is a scenario in which you extend UIWebView, so it needs additional delegate methods. If this is not what you want to do, just make your class implement the delegate, as per usual:

@interface FViewController <UIWebViewDelegate> 

Check out also this question and answer: Defining categories for protocols in Objective-C?

Community
  • 1
  • 1
TotoroTotoro
  • 17,524
  • 4
  • 45
  • 76
0

The author of this code is creating a category on FViewController that makes it conform to UIWebViewDelegate. Presumably, this category only implements UIWebViewDelegate methods. That can be useful if you want the source for that delegate be separate from the rest of the source. Especially in large classes, adding categories to the class instead of putting it al in the class definition can make everything more readable. The categories could be in separate source files, which leaves the core functionality of the class in the main implementation file for that class.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80