Under the trend of OC and Swift co-programming, I wrote iOS application using pure Swift for the first time, and recorded the first time I created a complete Swift App.

1. Create a project

Xcode: 12.2 Swift5, check the current Swift version

cmd+shift+nWhen creating a new project, the following returns:Compared to the previous versionLife CycleOptions are currently the main focusUIkit App DelegateforSwiftUI AppIs another category, please refer to it for detailsAlibaba tao department of technologyRelevant articles are explained in detail

Project style after creation:

2. Preparation

  1. Third party library management: currently usedCocoapods, may be adopted laterSPM,Apple Xcode built-in third-party management tools
  2. Constraint library:SnapKit
  3. The network library:Moya
  4. Json parsing library:HandyJSON SwiftyJSONEtc.
  5. Front-end print request log:HDWindowLogger(OC+Swift)
  6. Others: Refer to these recommendation libraries

3. Comment syntax for Swift

MARK: – // TODO: – // FIXME: //

4. Enter the project

1. Create projects

1. Delete itemsSceneDelegate.swiftTo replaceAppDelegate.swiftFile content to support lower versions such asiOS10. Note: The alternative content refers to the currently created projectLzcShop
2. Note: There will be a black screen when compiling the project, because inplistNo deletion in fileApplication Scene ManifestOptions are referenced hereUse XCode 11 to create a project that supports target earlier than iOS13

2. UseCocoapodsFor managing third-party libraries, see this articleAbout Swift using CocoapodsAnd this one is full of themSwift excellent library
3. Add the. Swift file to the project

To add files, you do not need to add swift files. Just like OC, you can add Cocoa Touch Class files, or you can inherit existing parent classes