One, foreword
When CHATTING with my friends last night, I talked about Swift5.x. Although the current project is mixed programming (OC+Swift), I want to practice a pure Swift project. I have considered SwiftUI, but there are restrictions on iOS, which only supports iOS13. So I plan to open a swift5.x + UIKit series. For the series, the web is cluttered, and good ones are charged; Of course, I can not blame others, after all, they spent time and energy; Similarly, although I am not so noble, on the one hand, I practice my skills by myself, on the other hand, I also want to share with everyone, communicate with them and make progress together.
2. New projects
To do good work, must first sharpen its tools
Before officially creating the project, please upgrade macOS to the latest (Big Sur), and then go to the App Store to upgrade Xcode, and install Xcode command line tool:
$ xcode-select --install
Copy the code
2.2. Create a project
- Open Xcode and select “Create a new Xcode Project”
- Select ios-app
- Select “Swift + UIKit” instead of “SwiftUI”
- Just click “Create” and ignore the code controls
- The following figure shows the successful creation
Write UI, delete main.storyboard
3.1. Delete the main. storyboard file
- Select Move to Trash
3.2. Modify “XcodeProject Configuration”
- Select “FirstTrain”
- Delete “Main” and tick off “iPad”, “Landscape Left”, “Landscape Right”
3.3. Modify info.plist
3.4. Modify appdelegate. swift
- My latest version has more ‘Lifecycle’ and needs to comment it out
- Annotated as follows
Then, use the shortcut “Command + B” to compile it (Product -> Clean Build Folder if you have compiled it before).
Create the first ViewController
4.1. Modify Appdelegate. swift to create UIWindow
4.2. Modify “ViewController” and add background color
4.3. Select the appropriate simulator
4.4 compile and run
OK! And you’re done!
Five, the summary
Some people say, well, storyboards are so convenient now, why are we doing this old-fashioned, hand-written code?
There are several reasons I would like to share with you:
- In college, I used various development tools: TurboC, VC6 (Win32, MFC), C++Builder; Then, you realize that if you start dragging and pulling and dragging, it’s really fast, but you’re going to miss a lot of the original stuff; On the other hand, if you’re good at writing code by hand, you’ll be much more comfortable using tools.
- People work as a team, so writing code, file conflicts are very easy to resolve, but with storyboards and XIb, it’s very difficult to resolve conflicts, although Apple has been working on that;
- This article focuses on practice, along with sharing and communication, so handwritten code is easier for everyone to look more intuitive (don’t worry, I will write notes).