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
+n
When creating a new project, the following returns:Compared to the previous versionLife Cycle
Options are currently the main focusUIkit App Delegate
forSwiftUI App
Is another category, please refer to it for detailsAlibaba tao department of technologyRelevant articles are explained in detail
Project style after creation:
2. Preparation
- Third party library management: currently used
Cocoapods
, may be adopted laterSPM
,Apple Xcode built-in third-party management tools - Constraint library:
SnapKit
- The network library:
Moya
- Json parsing library:
HandyJSON
、SwiftyJSON
Etc. - Front-end print request log:
HDWindowLogger
(OC+Swift) - Others: Refer to these recommendation libraries
3. Comment syntax for Swift
MARK: – // TODO: – // FIXME: //
4. Enter the project
1. Create projects
1. Delete itemsSceneDelegate.swift
To replaceAppDelegate.swift
File 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 inplist
No deletion in fileApplication Scene Manifest
Options are referenced hereUse XCode 11 to create a project that supports target earlier than iOS13
2. UseCocoapods
For 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