Shocked, the new company code is so!

I hope you are not scared of the title, the title is purely for fun.
has entered the new company for more than five days, saw the company part of the project code, said his idea. I’m not Daniel, not to say that the company code is not good. Just want to write code to pay attention to the following small problems.

1 AppDelegate is too complicated
- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions;

The program is too messy to start the method, the registration of the blue ring letter, whether to enter the boot page, etc. there are many operations, a lump of a long.

  • A
    solution can be encapsulated in the same function code in a method, such as the initialization module are placed in a League of friends – (void) registerUM method, and then call this code when you need initialization. At the very least, the code looks neat and tidy, and doesn’t seem so messy.
  • Solution two
    write an extension of the AppDelegate class, the method of a – (void) registerUM into the expansion, and then call in AppDelegate.m, which will reduce the amount of code in AppDelegate.m.
  • Solution three
    to write an extension of the AppDelegate class, with method swizzling, making the call to the system before the first call to define their own methods. Initialize the third party platform in your own method. This will not increase the AppDelegate.m code, but it should be noted that their own definition of the method can not be written in disorder.
2 hard coding too much

According to the need of user information in the type to determine the types of users such as students or teachers in the background of type project, return is the string “student”, “teacher”, do not know why not return a typeID client, when the user’s judgment directly [userModel.type isEqualToString:@] “student”; to determine the user type. Because there are a lot of projects in the project need to be such a judge, if there is a day back to the background of the “student” to “stu”, then how to do.

  • A solution to both
    background type returns a string or typeID, finally make a map on the client, an enumeration defined in model, then in setType type method according to the type of mapping background type a value in the enumeration. So when you can determine the user [userModel.etype = = userTypeStudent “]; judge. So even if the background to modify the value of type, we also need only in the model setType method will be the corresponding value of the modified line.
  • Solution two
    if you insist on using [userModel.type isEqualToString:@ “student”; it is best to “student” to define a macro bar. So after the background to make changes, only need to modify the macro.
3 ViewController – (void) viewDidLoad

Do not say viewController downsizing, at least not to do the initialization of the control, layout, and business logic are written at random – (void) viewDidLoad. The number of lines within the method will be too much, see the easy motion sickness. Somewhat similar

- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions;

In.

  • The solution can be a
    reference, initialization control, layout operation, business logic encapsulated into their respective methods and then call the corresponding method, although did not reduce the amount of code in VC, but at least no different function code in the case of mutual doping, you have me.
4 END

These issues are basically not much less than the technology cattle and cattle, but it is worth noting that some small problems. At the very least, make your code look neat, easy to read and easy to maintain. The highest level is to make our code screenshot to mobile phone wallpaper can do degree.