# data[].attributes.attachment_link.description
Apple 的科技帮助教育工作者利用强大的产品、支持和课程创造奇妙的学习体验，让学生们尽情释放创造力。

# data[].attributes.attachment_link.readable_text
我很喜欢的编程入门游戏，各方面都非常好。通关过程中深深体会到对解决复杂问题的逻辑条理思维受到强烈锻炼！随着使用深入也越来越感觉到不提供参考答案和更多的解决方案带来的极大限制。特别是很多关卡有n中解决方案，我非常非常渴望看到其他人的解决方案，这样可以扩宽我自己一直被限制的思考盲点，可是，没有！完全没有！太遗憾了

# data[].attributes.attachment_link.description
‎描述： Swift Playgrounds 让学习编程和构建真实 App 变得妙趣横生。你可以在"编程入门"的指导下通过互动学习来闯关，并在"开始使用 App"中学习构建 App 的基础知识。你还可以尝试众多挑战及示例，从中探索独一无二的编程经验。 Swift Playgrounds 无需任何编程经验，特别适合初学者，老少咸宜。整个 App 旨在帮助你学习 Swift 和 SwiftUI。Swift 和 SwiftUI 是 Apple 开发的强大编程技术，时下许多流行 App 都是全球专业人士使用这些技术开发而成。正由于充分利用了 iPad 和真实 iOS SDK 的优势，Swift Pl...

# data[].attributes.headline
《人人能编程：学前班至低年级教学篇》

# data[].attributes.subject
《人人能编程：学前班至低年级教学篇》

# data[].attributes.attachment_link.readable_text
Here, you'll find information about the how to use the Swift programming language.

If you're new to Swift, check out A Swift Tour in The Swift Programming Language, for a quick introduction to the most important concepts and features of the language.

Installing Swift

The first step to using Swift is to download and install the compiler and other required components. Go to the Download page and follow the instructions for your target platform.

In order to follow along with the examples below, make sure to add Swift to your $PATH.

On macOS

The default location for the downloadable toolchain on macOS is /Library/Developer/Toolchains. You can make the latest installed toolchain available for use from the terminal with the following command:

To select any other installed toolchain, use its identifier in the TOOLCHAINS variable. The identifier can be found in toolchain's Info.plist file.

On Linux

Install required dependencies:

If you installed the Swift toolchain on Linux to a directory other than the system root, you will need to run the following command, using the actual path of your Swift installation:

On Windows

Dependencies

Swift has the following general dependencies:

Windows has the following additional platform specific dependencies:

Enabling Developer Mode

In order to develop applications, particularly with the Swift Package Manager, you will need to enable developer mode. Please see Microsoft's documentation for instructions for enabling developer mode.

Installation Instructions

Install using the Windows Package Manager

The Windows Package Manager can be found in the App Store or be installed directly.

1. Install required dependencies:

The platform dependencies cannot be installed through the Windows Package Manager as the install rules do not install the components necessary. They will be installed through Visual Studio installer.

winget install Git.Git winget install Python.Python.3 --version 3.7.8150.0 curl -sOL https://aka.ms/vs/16/release/vs_community.exe start /w vs_community.exe --passive --wait --norestart --nocache ^ --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community" ^ --add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^ --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 del /q vs_community.exe

2. Install Swift:

Swift can be installed through the official installer directly, or using the Windows Package Manager as well. Notice that Windows Package Manager release may be behind the official release.

A Swift toolchain will be installed at %SystemDrive%\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain. A compatible Swift SDK will be installed at %SystemDrive%\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk.

Traditional Installation

NOTE: The traditional installation process is required for Swift older than 5.4.2.

Swift has been tested with Visual Studio 2019. You will need to install Visual Studio with the following components. The installer for Swift is available in the Download section. The toolchain on Windows is installed to %SystemDrive%\Library\Developer\Toolchains.

The following Visual Studio components are required:

MSVC v142 - VS 2019 C++ x64/x86 build tools (Latest)

Microsoft.VisualStudio.Component.VC.Tools.x86.x64

Windows 10 SDK (10.0.17763.0)

Microsoft.VisualStudio.Component.Windows10SDK.17763

The following additional Visual Studio components are recommended:

The following additional Visual Studio component is suggested:

C++ CMake tools for Windows

Microsoft.VisualStudio.Component.VC.CMake.Project

Support Files

NOTE: This is only required for versions older than 5.4.2

In order to make the Windows SDK accessible to Swift, it is necessary to deploy a few files into the Windows SDK. The following will modify your Visual Studio Installation, and as such will require to be run from an (elevated) "Administrator" x86 Native Tools for VS2019 Command Prompt.

copy /Y %SDKROOT%\usr\share\ucrt.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" copy /Y %SDKROOT%\usr\share\visualc.modulemap "%VCToolsInstallDir%\include\module.modulemap" copy /Y %SDKROOT%\usr\share\visualc.apinotes "%VCToolsInstallDir%\include\visualc.apinotes" copy /Y %SDKROOT%\usr\share\winsdk.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"

Because it is installing the files into the Visual Studio image, the files will need to be copied each time Visual Studio is updated.

If Visual Studio is updated, you may have to repair the installation. See Microsoft's instructions for repairing installed programs.

Swift Version

You can verify that you are running the expected version of Swift by entering the swift command and passing the --version flag:

The -dev suffix on the version number is used to indicate that it's a development build, not a released version.

Using the REPL

If you run the swift command without any other arguments, you'll launch the REPL, an interactive shell that will read, evaluate, and print the results of any Swift code you enter.

Interacting with the REPL is a great way to experiment with Swift. For example, if you enter the expression 1 + 2, the result of the expression, 3, is printed on the next line:

You can assign values to constants and variables, and use them in subsequent lines. For instance, the String value Hello, world! can be assigned to the constant greeting, and then passed as an argument to the print(_:) function:

If you enter an invalid expression, the REPL will print an error showing where the problem occurred:

You can use the up-arrow and down-arrow keys ( ↑ and ↓) to cycle through previous lines entered into the REPL. This allows you to make a slight change to a previous expression without retyping the entire line, and is especially convenient for fixing errors like the one in the previous example:

Another useful feature of the REPL is that it can automatically suggest functions and methods that can be used in a particular context. For example, if you enter re after a dot operator on a String value and then hit the tab key ( ⇥), the REPL will give a list of available completions like remove(at:) and replaceSubrange(bounds:with:):

All of the functionality of Swift is available to you from the REPL, from writing control flow statements to declaring and instantiating structures and classes.

You can also import any available system modules, such as Darwin on macOS and Glibc on Linux:

On macOS

On Linux

On Windows

The REPL depends on Python bindings. You must ensure that Python 3.7 is available in the path. The following command adds Python 3.7 from Visual Studio to %PATH% so that it can be used:

path %ProgramFiles(x86)%\Microsoft Visual Studio\Shared\Python37_64;%PATH%

Because the Windows installation separates out the SDK from the toolchain, a few extra parameters must be passed to the REPL. This allows you to use multiple different SDKs with the same toolchain.

set SWIFTFLAGS=-sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows swift repl -target x86_64-unknown-windows-msvc %SWIFTFLAGS%

Using the Package Manager

Swift package manager provides a convention-based system for building libraries and executables, and sharing code across different packages.

These examples assume you have made swift available in your path; see Installing for more information. Once available, you can invoke the package manager tools: swift package, swift run, swift build and swift test.

Creating a Package

To create a new Swift package, first create and enter a directory named Hello:

Every package must have a manifest file called Package.swift in its root directory. You can create a minimal package named Hello using:

By default the init command will create a library package directory structure:

You can use swift build to build a package. This will download, resolve and compile dependencies mentioned in the manifest file Package.swift.

To run the tests for a package, use: swift test

Building an Executable

A target is considered as an executable if it contains a file named main.swift. The package manager will compile that file into a binary executable.

In this example, the package will produce an executable named Hello that outputs "Hello, world!".

First create and enter a directory called Hello:

Now run the swift package's init command with executable type:

Use the swift run command to build and run the executable:

Note: Since there is only one executable in this package, we can omit the executable name from the swift run command.

You can also compile the package by running the swift build command and then run the binary from .build directory:

As a next step, let's define a new sayHello(name:) function in a new source file, and have the executable call that instead of calling print(_:) directly.

Working with Multiple Source Files

Create a new file in the Sources/Hello directory called Greeter.swift, and enter the following code:

The sayHello(name:) function takes a single String argument and prints our "Hello" greeting before, substituting the word "World" with the function argument.

Now, open main.swift again, and replace the existing contents with the following code:

Rather than using a hardcoded name as before, main.swift now reads from the command line arguments. And instead of invoking print(_:) directly, main.swift now calls the sayHello(name:) method. Because the method is part of the Hello module, no import statement is necessary.

Run swift run and try out the new version of Hello:

To learn about the Swift Package Manager, including how to build modules, import dependencies, and map system libraries, see the Swift Package Manager section of the website.

Using the LLDB Debugger

You can use the LLDB debugger to run Swift programs step-by-step, set breakpoints, and inspect and modify program state.

As an example, consider the following Swift code, which defines a factorial(n:) function, and prints the result of calling that function:

Create a file named Factorial.swift with the code above, and run the swiftc command, passing the filename as a command line argument, along with the-g option to generate debug information. This will create an executable named Factorial in the current directory.

Instead of running the Factorial program directly, run it through the LLDB debugger by passing it as a command line argument to the lldb command.

This will start an interactive console that allows you to run LLDB commands.

For more information about LLDB commands, see the LLDB Tutorial.

The print command can evaluate Swift expressions as well.

Use the continue ( c) command to resume the process until the breakpoint is hit again.

Use the print ( p) command again to inspect the value of the n parameter for the second call to factorial(n:).

Use the breakpoint disable ( br di) command to disable all breakpoints and the continue ( c) command to have the process run until it exits.

Now that you've been introduced to the Swift REPL, build system, and debugger, here are a few suggestions for what to do next:

# data[].attributes.attachment_link.description
Here, you'll find information about the how to use the Swift programming language. If you're new to Swift, check out A Swift Tour in The Swift Programming Language, for a quick introduction to the most important concepts and features of the language.

# data[].attributes.attachment_link.description
Apple Teacher 计划是免费的专业学习计划，专为支持和表扬运用 Apple 产品来教授和学习的教育工作者而设。

# data[].attributes.attachment_link.description
‎Swift Playgrounds 让学习编程和构建真实 App 变得妙趣横生。你可以在"编程入门"的指导下通过互动学习来闯关，并在"开始使用 App"中学习构建 App 的基础知识。你还可以尝试众多挑战及示例，从中探索独一无二的编程经验。 Swift Playgrounds 无需任何编程经验，特别适合初学者，老少咸宜。整个 App 旨在帮助你学习 Swift 和 SwiftUI。Swift 和 SwiftUI 是 Apple 开发的强大编程技术，时下许多流行 App 都是全球专业人士使用这些技术开发而成。正由于充分利用了真实框架的优势，Swift Playgrounds 带来了前所未有的学...

# data[].attributes.headline
《人人能编程：解谜闯关》学生指南

# data[].attributes.subject
《人人能编程：解谜闯关》学生指南

# data[].attributes.headline
《使用 Swift 开发》师资培训

# data[].attributes.subject
《使用 Swift 开发》师资培训

# data[].attributes.attachment_link.description
© 2022 Apple Education through Canvas LMS All Rights Reserved.

# data[].attributes.attachment_link.description
Xcode 包含了为 iPhone、iPad、Mac、Apple Watch 和 Apple TV 打造出色 App 所需的一切资源。

# data[].attributes.headline
《人人能编程：解谜闯关》教师指南

# data[].attributes.subject
《人人能编程：解谜闯关》教师指南

# data[].attributes.attachment_link.description
现在正是在 Apple 平台上进行开发的绝佳时机。

# data[].attributes.headline
《人人能编程：探险闯关》学生指南

# data[].attributes.subject
《人人能编程：探险闯关》学生指南

# data[].attributes.headline
《人人能编程：探险闯关》教师指南

# data[].attributes.subject
《人人能编程：探险闯关》教师指南

# data[].attributes.attachment_link.description
查找用于编写 Swift 代码的下载项目、参考文档和示例代码。

# data[].attributes.headline
《使用Swift开发：探索》学生指南

# data[].attributes.subject
《使用Swift开发：探索》学生指南

# data[].attributes.headline
《使用Swift开发：探索》教师指南

# data[].attributes.subject
《使用Swift开发：探索》教师指南

# data[].attributes.body
Tello：https://playgroundbook.ryzerobotics.com/locales.json

Sphero：https://playgrounds.sphero.com/locales.json

legoEV3:https://ev3.api.education.lego.com/locales.json

# data[].attributes.attachment_link.readable_text
Watch the Keynote and State of the Union

The Apple Worldwide Developers Conference kicks off with exciting reveals, inspiration, and new opportunities. Join the worldwide developer community for an in-depth look at the future of Apple platforms, directly from Apple Park.

Apple Keynote
June 7, 10 a.m. PDT

State of the Union
June 7, 2 p.m. PDT

# data[].attributes.attachment_link.description
The Apple Worldwide Developers Conference kicks off with exciting reveals, inspiration, and new opportunities. Join the worldwide developer community for an in-depth look at the future of Apple platforms, directly from Apple Park. Apple Keynote June 7, 10 a.m. PDT State of the Union June 7, 2 p.m. PDT

# data[].attributes.attachment_link.description
Take a look at Apple WWDC Scholarship winners from all around the world as well as their winning submissions!