What is the most important thing for a programmer? No document!
What is the most annoying thing for a programmer? Write document!
The above is called the programmer’s tangled, Unbelievable! Recently I caught so tangled thing, the company has a project called “Life Project”, established in two years ago, was already on the shelves, but the effect is not good, but was forced off the shelf off the project, but the life is so wonderful, two years after the market in urgent need of Every dog has his day, is something this “Life Project”, so it is not +1s, ahem, back to life, however, when all team members had left, no documentation! No one handover!
Who will take over? The leader said to me, I was working on another project group, I say I am a group of other projects, how can go back the project group, leader said to me: “the organization has already been decided by you, when the total book… Well, you to restart the project”. In my heart infinite emotion, at that time read two sentences: “Gou Li country life and death… Keke”
So I came to the pit father of the project team, oh, the project team is only one of me!
And at this time, I just learned iOS a year…..
As a responsible young people who have a good new world, since the organization has already decided, I am a party member, this time I do not go up?! With this determination, I began a wonderful trip to restart.
First of all, get permission to download the code from the server and found that the project can not run!
A lot of Warning, Error!!
Not to say that already on the line? I looked at the submission of the log, the last one is to modify the build number, released to the App Store, how can not run up?
Go read wrong, most is the lack of documents, is the lack of framework, the third party libraries and the like, but the strange thing is before it can run ah, then through the N layer to find the relationship between the original members of the project team, that is, on the phone, the project relies on the library management time is used static library method, now the buddy cocoapods flying, a pod update fix all year, however, I don’t know cocoapods issued no, at least not using this project, so how to manage the third party libraries and components of many?
The answer is another project, the required components and libraries, compiled into a CommonLib Frameworks, and then import the main project framework. Today, the Internet can also find how to make framework documents, no longer repeat, we look for it.
As shown below, this is a part of the screenshot I have imported
The original is not imported Framework, will appear error, know the reason is easy to do, and I found this Framework code, join in, indeed as expected OK, so far, we finally build success.
It is also found that the project was supported by the minimum version is iOS 6.1, well, yes, when the iOS 10.2 release, the project is still in the 6.1
minimum support version
Roll up sleeves, dry gas
Well, Tucao finished, the dry have to do it, so I began to think, how to receive such a project?
upgrade migration plan
The above is my mind map, of course, while doing supplement, as Agam said, you never know where the next pit, take a step further
The following in accordance with the sequence of mind map to do one by one!
1 migrate to Cocoapod
1 rely on the library is not easy to manage, their own way of managing the human flesh rely on the pain of the library we all understand, this is the reason for the prevalence of
2 there is no version management, you can only open the project, the naked eye to distinguish what version is used, for example, MJRefresh has been updated to 3, and the project is what version, do not know
The solution is, of course, as the title says, migrate to Cocoapod
Mind map, you can see my problems
1 dependency statistics
I have to know which items are used in the third party library, which has the Cocoapods version, which does not, this part, I used this approach, open the project, human statistics, there are so many pictures below!!!
No way, only to do so, then we found that so many third party libraries, some are not used, how to find? Go global search
I guess some components are no longer in use, but there is no time to clean up, then left to posterity a lot of useless code, also reminds the reader, pay attention to this point, do not harm to others.
After the final cleanup of the components, not as much as above, about twenty or so, sorted into a podfile file, as follows
Note that after each component name, there is a specified version number, in the next section of the switch has been mentioned, how to determine the version number
This is the most used part of the cocoapods search function
Pod search AFNetworking
Now ready to work, is to switch!
First of all, the need to remove the project configuration file inside a lot of configuration items, the principle is the need to configure a static library, here are deleted, the goal is to have all relevant CommonLibARC projects in clean configuration
For example, the following, the configuration of a lot of very miscellaneous here I do not one shot, only the above 2 for reference
Then, is part of the Cocoapods, there are a lot of tutorials on the network, we need to establish podfile, and then use the pod install command. This will generate a xcworkspace file, you need to open the project from here, as shown below, all third components are managed under the Pods project
At the same time, it also produces a large number of error, the reason is the need to develop the library version of podfile, but we do not know what version of two years ago, with the release of the change, the method name may change, or even kill, so build will fail.
My method is:
1 pod search, and see what component version, first choose a relatively stable version, for example, MJRefresh is the latest version of 3.1.12, calculated from the number and time, when the engineering must be very old, may be 1.x, but considering the time component is also necessary to upgrade, I the final selection of the 3 version, this version of the user, and not too old
It produces a large number of method name changes, their flesh MEIZHE one change, for example as follows
MJRefresh method name change
2 error endless
I come to this step is the most painful, because several days are not compiled successfully, because when the compiler encounters some error not down in the compile, so you see for example 3 error, solve them, then build, and found out 5 more, this is the spirit of torture, kill tolerance. And I can not submit the code, because every time I only solve part of the problem, can only be temporary to the local, to compile successfully submitted to the remote.
3 CocoaLumberjack—> DDLog
Here special mention CocoaLumberjack, which is the log framework for a set of fast, simple, powerful and flexible at the same time, we mainly used in the DDlog project, this is already in the component, but DDlog need to define a log level, below the level of log is no longer displayed.
In the source code, is used in each place is in the.M file defines a global search, you will find a lot of the same code, verbose
a lot of repetitive definitions
defines the log level
Therefore, I will change it to the PCH file, the definition of its level in the appdelegate, so only once, global general
Here to mention a Crashlytics, which is a very useful statistical Crash tools, easy to use, easy to use, 5 minutes to get a strong Amway hair. The original project has also been used, but the account password is not handed down, I take this opportunity to update to the latest version
Well, at this point, all the migration work has been completed, I am excited to press Command+B, Build Success!!!
However, the vast number of warning has not been solved
3 component transition method
There are some components, involving a wide range, replace them particularly troublesome, in order not to affect the progress of the moment I decided to start up, then slowly back to the optimization, so the transition method, without cocoapod management, but the Framework must be removed, otherwise there will be conflict, how to do it
Simple drag and drop, directly into the component folder add into project!
Start up again!
2 iOS 8 upgrade
At this time of the project, after years of vicissitudes, he finally ran up, but the project is still in the moment of history, iOS 6.1!!!!
Then, we went to Apple’s official website to view the proportion of each version, as shown in the figure, as of 2017.01.04, the amount, has not seen less than 8, plus a piece of only 6%
Here is a query link: https://developer.apple.com/support/app-store/
version of the iOS accounted for
So, I started a new journey, upgrade to iOS 8, why is it a 8?
Big step afraid to pull eggs!
As shown in the top diagram, most of the warning is concentrated in the following areas
2.1 Method Deprecation
Apple is a cheating company, with the upgrade version of the iOS class, and the methods of the native system has changed, a new alternative method, the system will prompt us to get rid of, and is a toil live, is not possible to change it, this project is the most encountered, UILabel method. For the calculation of the font size
2.2 Format String Issue
This is a good solution, most of the system can help solve, I believe you must have met
Format String Issue
2.3 Conflicting Return Type
This is similar to the first, the system method upgrades, according to the prompts can be changed
Conflicting Return Type
2.4 missing [super awakeFromNib]
This is the pit dad’s code style lead, all UITableViewCell are not [super awakeFromNib] method.
You know, we have RootClass in engineering practice such as RootTableViewCell, cell are all inherited from RootClass, in RootClass to achieve some of the basic properties and methods of the overall situation, we usually write is the awakeFromNib method, this method makes the loss of all subclasses of global settings to the parent class does not inherit.
Not exactly the same, must be added
missing [super awakeFromNib]
missing [super awakeFromNib]
2.5 ARC bug
The Bug estimation is handshaken wrong, but it’s the trouble investigation.
The phenomenon is a page at the time of debug is normal, but the installation package to the mobile phone will flash back, because when debugging has been good, so can’t catch Crash, this time is when the Crashlytics display skills to the full Crashlytics web site, we, can clearly see the crash log, as follows, the cause of the collapse is shown here unrecognized selector also said an object called the unknown method, according to the Log instructions, is actually a NSDictionary call to the objectAtIndex: method
Crashlytics crash log
Look at the log in fact there is a specific number of rows in the 305 crash line, the line code is as follows:
ObjectAtIndex is really called the method, but the yLabelsStringArray is indeed a NSArray ah! How can become NSDictionary? Where is wrong
Look at the students will find that the ARC parameters of the attribute is assign, we know that assign is used for non pointer variables, basic data types, and not on the reference count of +1, also said that the NSArray is created, it is immediately released, which led to collapse, so only can be changed into strong
So far, the entire project build success!!
3 increase Log
Well, we have an old iOS project, successfully upgraded the most commonly used in engineering, but so far we don’t even have to understand how the project is doing, that is to say we don’t have to understand the business logic, due to lack of document, how to grasp the business logic into big trouble, we can only through their own play this App, each page to little to operate. So in order to facilitate the rapid understanding of the code architecture and business understanding, need Log to help us understand the project
The original project almost no Log….
Fortunately, this project all ViewController are inherited from a RootController, then add log in BaseViewController, the US, in the Debug, with the operation, we can know which page which corresponds to ViewController, here is the use of the above mentioned DDLog
DDLogInfo (@ “% @ viewDidLoad, [self class]); #endif
DDLogInfo (@ “% @ viewWillAppear, [self class]); #endif
3.2 Network Request Log
Similarly, we call the interface is also unknown, must also be on the network Log, in order to facilitate debugging, I print out the URL, Method (GET/POST), parameters, Header
Why do you want to print out a Header, because Header has access token, so that we can use Postman to do the need to log in to the interface debugging, without having to click on the app to trigger the request
Similarly, Amway Postman, very easy to use network debugging tools
3.3 DB file path
The project also has a database, using the simulator debugging, in fact, we can open the database to run App, just print out the database file path can be convenient for our future debugging
4 invalid code removal
After the Log is completed, we can be at ease to sort out the business logic.
After communicating with the demand side, APP some features can be removed, and then delete the rhythm of the code
This part is relatively simple, useless code to find out, Delete can, or coolies live
5.1 modular directory
Directory structure in the project is also a need to pay attention to the place, I use the most widely used MVC structure
5.2 network layer
Engineering is the most common AFNetworking, which is still part of physical activity
1 first need to sort out the server address, including Dev (Development), Stg (on line), Pro (production) three environments
2 need to sort out all the interface documentation, which is by Network Log
3 network layer logic, you need to read the code, understand how to build the network layer, this part can be temporarily for a while
5.3 database collation
Many of the project data is inside the database, from the dependence on the library, the use of FMDB, is also a common open source library
I use MesaSQLite as client
This part of the work, it is necessary to cooperate with someone, put a temporary release
6 storyboard bloated
The original project, so the ViewController, that is all the ViewController in a storyboard, so when you want to open the storyboard, need to wait, uh, about 3min, for everyone to see, I have noted that the following zoom to 6.25%, so a huge and bloated storyboard, i.e. no good management, no expansion, open it and serious Caton
This part of my writing for a moment, because it has not been implemented
6.1 program 1: storyboard reference
To solve this problem, Apple introduced the concept of Storyboard References in iOS 9. Storyboard References allows you to refer to other storyboard in viewController from segue. This means that you can maintain a different functional modularity, while the size of the Storyboard is small and easy to manage. Not only is it easy to understand, but when you work with a team, it’s easier to merge.
But our project is currently in 8, need to consider whether to upgrade to 9
6.2 program two: storyboard split into Xib
The benefits of Storyboard is that one eye can see the logic structure of app, it is good for understanding the whole project all of the jump page, but obviously he cannot harm, the management of a large project, so a lot of engineering scheme is Xib, a ViewController, a corresponding Xib, instead of storyboard, like this it is particularly convenient
But the problem is: the original project storyboard, there may be more than and 30 ViewController, how to migrate in the past is a troublesome thing