Thumbs up comments, feel useful friends can pay attention to the author public number iOS growth refers to north, continue to update

This is the 15th day of the Swift 100 Days series, which is a record of my Swift learning.

As mentioned above, we need to start implementing a truly usable application.

He that will do his work well must first sharpen his tools

As an introduction to programming in a general sense, like any other textbook, we need to take a moment to sort out the use of Xcode, the Integrated Development Environment IDE for iOS.

Keep up with time

A qualified iOS developer should be sensitive to the latest information on the official website. It is recommended to briefly check News and Updates for the latest News notifications at least once a month. This is what iOS developers usually talk about, including but not limited to the latest approval standards and new features that can be released on the App Store.

After WWDC each year, a new version of iOS comes along, which is an important time for iOS developers. So the WWDC module on the official website is extremely important for iOS developers.

Xcode

Xcode is a Mac application for building applications for iOS, macOS, tvOS and watchOS.

As a guide to using Xcode, let’s first discuss how to download/update Xcode.

Download Xcode from the Developer official website

Go to the More Downloads for Apple Developers website and select the version of Xcode you need.

To enter this page, you need to have a Developer account on the Developer website.

It can be free or paid.

After downloading Xcode, open and unzip the.xip file, which takes some time. Then drag and drop the xcode. app file into the ~ /Applications folder. Finally, launch the Xcode application. Then it pops up:

Click the Install button at this prompt. Xcode will try to install the Xcode command line tool on the Mac. These are CLI tools for compiling applications using Xcode.

If you really don’t want to sign up for a developer account, you can also use Xcode Releases to get a compressed file of Xcode. Then repeat the steps above and install Xcode.

update

The downside of manually installing Xcode through a developer is that Xcode does not automatically update. However, this is not necessarily a bad thing, you can use this method to install multiple versions of Xcode side by side. This is useful for debugging or trying out Beta versions of Xcode.

One of the advantages of keeping up with The Times is to be exposed to new things at any time, but due to various problems such as stability. Usually our package Xcode is not up to date.

Download/update Xcode from the Mac App Store

A great way to keep you up to date with Xcode is to download It using the Mac App Store.

  • Open the Mac App Store and log in with your Apple ID
  • In the search box on the left, search for Xcode
  • Click the Get/Install button in the upper right corner to download and Install Xcode

Downloading Xcode through the App Store is generally a bit slow. But now that you’re done, you’ll be notified of the updates as soon as the official Xcode is updated.

When updating Xcode via the App Store, you can’t install multiple versions of Xcode at the same time, and it’s hard to degrade the version.

mas-cli

One way to avoid slow App Store downloads is to use the MAS-CLI command line tool.

Mac App Store a simple command line tool designed for scripting and automation.

$ mas list409183694 Keynote (10.3.5) 1380446739 (2.2.0) 1450874784 Transporter (1.2)Copy the code

It lists the tools you currently download from the App Store

Update your unupdated application with the upgrade command.

$ mas upgrade
or
$ mas upgrade 409183694
Copy the code

The only downside to the command-line tool is that it must be downloaded from the App Store in order to upgrade by command.

what new

Xcode 12 has two major updates that you may want to be aware of

More labels

The new multi-tab feature allows you to open multiple files simultaneously in the same Window and allows you to arrange them. Before Xcode 11, there was only one TAB in the same Window.

Code completion optimization

Xcode 12 optimizes the way code completion works.

The new completion UI displays only the required information and takes up less screen space when typing. Moreover, the rendering speed of completion is much faster, so the coding can continue at the fastest speed.

Playground

Write some Swift code quickly using Playground in Xcode, try out the new Swift syntax, or improve your Swift algorithm skills. Xcode Playground is a great way to learn Swift programming.

So far, all the examples we’ve needed can be debugged on Playground.

Before we actually use Xcode to create the project, let’s take a closer look at the use of Playground.

Sidebar (Results/live)

Each time you enter a Swift statement in the editor, all the code in the Playground page is evaluated and the results are displayed in the sidebar. The source code editor works fine and displays code completion hints and syntax errors in real time.

Aside from the area for typing code, the Playground module is probably the most useful as a learning tool.

  • Hover over a delimited value, then click the eye icon for a quick look
  • Click the rectangle button to display the results inline in the code
According to the results

Displaying results has two advantages, one is that the results can be displayed inline in the code, and the other is that for arrays or algorithmic programs, we can see the results of the calculation

The result box also supports scaling, and the sidebar also has the number of loop statements.

If you need a simple line graph, you can generate a simple line graph by displaying the results

debugging

Hold down the Command key while you click in the code. A small menu pops up. This works in Xcode as well as in Playground. There are several options

  • Jump to DefinitionJumps to the location where the variable was first defined in the code
  • Show Quick HelpInformation about symbols and code documentation are displayed
  • CallersHelps identifies where code calls a particular function

Live View

In the previous example we talked about the use of the Textfield control, which we can only do by quickly viewing the style of the display.

But we can also run our Textfield control in real time.

Type the following code in Playground

import Foundation
import UIKit
import PlaygroundSupport

let frame = CGRect(x: 0.0, y: 0.0, width: 150.0, height: 30.0)
let customView = UITextField(frame: frame)
customView.backgroundColor = UIColor.white
customView.placeholder = "redColor"
customView.tintColor = UIColor.orange
PlaygroundPage.current.liveView = customView
Copy the code

Run the code and go to Editor -> Live View to see a Live screen on the right side of the page.

The Swift Playgrounds series teaches programming in this way.

Segmented run

In Playground, you can even run code to specific lines. Move your mouse over the gutter, row number to the left of the editor. When you hover over the line number, a blue play button appears. Clicking the Play button on the row runs the code to that point. Very handy for viewing intermediate results.

Markup

In the debugging example we showed how to view code documents. Swift uses Markup to create a Quick Helper for code that displays formatted text in render document mode.

Use /// syntactically or nested within /**/

///
///
///
or
/ * * /
Copy the code

The main thing to notice is the spacing between characters

Format Quick Help (Quick Helper)

When creating a method or custom component library, it is a good practice to add comments when appropriate. Here I’ll show you how to customize a quick help using Markup.

Our goal is to implement a quick help document as shown above

It is divided into the following parts

  • Summary: 12 code completion optimization.
  • Declaration:Method multiple object definition header, does not contain{}Part, cannot be modified, automatically generated
  • **Discussion: ** describes the topic section, where you can insert code, use ordered unordered lists, add bold, italic, references, and even you can insert links
    • Important: Define emphasis
    • Author: Defines the Author
    • Version: Defines the Version information
  • Parameter and Parameters: the syntax is different for a single Parameter and for multiple Parameters
  • Throws an exception
  • Returns Returns
  • Declaraed In: The location of the definition, which cannot be modified, is generated automatically

Thus, we can define a Quick Helper using Mark Up

// -parameter newElement: if there is only one Parameter, use Parameter
/ * * descriptions, pay attention to division to the topic content Here is the overall expression Can be inserted into a variety of fonts bold italic * * * * * * ` reference ` var can insert code Numbers = [1, 2, 3, 4, Numbers. Append (100) print(numbers) // Prints "[1, 2, 3, 4, 5, 100]" I'm iOS growth refers to the north * I am iOS growth refers to the north Find More * * * * [iOS growth refers to the north] (https://juejin.cn/user/3298190611456638) can increase the important information - important: This is an emphasis on -parameters: -element: This is the parameter *1* -element1: -throws: Throws an exception with Complexity. Throws must be defined for this section. - Returns: This section defines the return value, which must be displayed in Quick Helper. -author: iOS growth indicates north -version: Version 1.0.0 */

func showInfo(_ element: Int._ element1: Int) throws -> Int{}Copy the code

Pay attention to what time

  • Parameters, Parameter, Returns, and Throws are prompted only if they exist
  • Pay attention to the format, usetabSee carrying out null values

Making the Playground document

The author used the paginated Playground for the previous Demo, for which he created his own Demo management document using Markup

The author uses Markup to implement a list of articles and supports the jump of multiple pages

/*: # 100 Days Of Swift **Autor** iOS [icon](icon.png) - [Day1 - First steps in Swift](Day1) - [Day2 - Complex data types](Day2) - [Day3 - Operators and conditions](Day3) - [Day4 - Loops](Day4) **** [Next](@next) */
Copy the code

summary

There are many more uses of Markup that I won’t go into here, but as an ios-only blog, Markup can be used on Playground for at least the first 15 days of this series. Later, I may create a separate Playground for readers to play with the code on the iPad.

conclusion

Today we mainly cover Xcode downloads and updates, and how Playground has been used to learn iOS. Introduces the powerful Markup syntax in Swift by the way.