http://blog.sunnyxx.com/2015/12/19/self-manager-pattern-in-ios/ was the inspiration for this article the significance of this model is done it ourselves, not to give others trouble, let you pure point of function. For example: You want to implement a sharing feature. Maybe you need to share in many places, so you can’t write in every place, so you need to separate the sharing function, right, and make it pure.

+ (void)wxShareWithImages:(NSArray *)images shareTitle:(NSString *)shareTitle shareContent:(NSString *)shareContent shareURLString:(NSString *)shareURLString response:(KZWResponseCallback)response;
Copy the code

All you have to do is create a separate ShareService so that wherever you share it you can just call this method and you don’t have to do anything. Then you’ll find that you can take a lot of services out of your app and cut down on redundant code. Pure! In the example of chestnut is the chestnut of the author’s original text, why I want to cite the same chestnut, because I also have to say: microblogging avatar everywhere, you need to click the avatar to jump to the personal center, as well as a variety of big V effects including the avatar. The code looks like this:

- (void)selfManagedConfigureWithAvatarURL:(NSURL *)URL VIPInfo:(id)info UID:(NSString *)UID { [self ConfigureWithAvatarURL: URL VIPInfo: info tapped: ^ {/ / assume that App structure is the Root - > TabBar - > Navigation - > ViewController UITabBarController *tabBarControler = (id)[UIApplication.sharedApplication.delegate.window.rootViewController;  UINavigationController *navigationController = tabBarControler.selectedViewController; / / create the user information View Controller FDUserProfileViewController * profileViewController = [FDUserProfileViewController viewControllerWithUID:UID]; [navigationController pushViewController:profileViewController animated:YES]; }]; }Copy the code

One problem you’ll notice is that the jump is written in the view. We all know that the jump method needs to call the controller, which is not available in the view, so it’s very inconvenient to declare it, right? In this case, you need the Router, and you can jump to any hop, hahaha. Make your self-mannage pure. One last thing: if you have a lot of WebViews in your app, is that a Webview declares a Controller? We don’t really need it, we just need a Controller, we just pass in the URL and we open up a WebView and we don’t need so many controllers, and then we can put the Router in there. So you can do that, the navigation bar of the WebView, whether you need to return, whether you need to titler, whether you need to pass the full URL or just pass the path, whether you test the online environment and so on are all configurable. Isn’t that cool? Hahaha. Make your self-mannage pure. Here I am just an extension of this design pattern, and I hope you can enjoy it.