preface

With the official release of Swift3, our project also started the Swift3 migration. With tears in your eyes, do it!! Talk is cheap, show me the code

Alamofire

Alamofire is an excellent network loading library developed by Swift. It has been used for network loading in the previous project, but since Swift3, Alamofire supports iOS9+ at least, which is undoubtedly bad news for us who need to adapt iOS8+. There are two methods for this situation:

  1. Find an alternative library – FOR this purpose I replaced Just with a lightweight network loading library. I won’t go into too much detail on the use of Just here, but interested readers can read the following article -Just- a lightweight network loading library
  2. Their implementation

Class conversion section

Swift3 started with Apple removing the Foundation framework, and some classes changed as a result:

This is the class that will be replaced in this update, and there will probably be more (oh, my God)

GCD

Swift3 has made a big change to GCD and is now swift-enabled. It is now easy to use GCD

Application level

After I had painstakingly eliminated all errors and warnings, I happily ran the application, only to see it go black. Find out why… Solution:

The problem is this method, where Xcode8 does not automatically convert, and does not report errors or warnings

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool  
Copy the code