Swift's new language development

Source: Internet
Author: User

Book folder:

First, Welcome to Swift

Second, Language Guide

Third, Language Reference

/*

Translator's nonsense:

A few hours ago stayed up to see WWDC, all kinds of excitement, this year very material Ah! When we see swift coming out, I suddenly get dumbfounded and learn a new language. This article is from Apple's official "The Swift Programming Language" book, about 500 pages, downloaded on the Apple website. Swift everyone has not actually used, this translation must have a variety of errors and omissions, you can forgive me, I will constantly update the amendments.

--(blog park, Sina Weibo) Galbrain the Great

*/

First, Welcome to Swift

1. About Swift

Swift is a new programming language for iOS and OS X apps, built in the best C and Objective-c languages, without the C language compatibility restrictions. Swift uses a secure programming model that adds modern features to make programming easier, more flexible, and more fun. Swift's support for the mature and pampered Cocoa and Cocoa Touch Framework is another opportunity to envision software development.

  Swift has been brewing for years, and Apple has laid the foundation for swift by improving existing compilers, debuggers, and framework structures, and has simplified memory management through automatic Reference counting (ARC). Swift's framework is built on a solid foundation and cocoa, and has been modernized and thoroughly standardized. Objective-c itself has evolved to support blocks, collection literals and modules, enabling the framework to use modern language technology without interruption. Thanks to this foundation, we are able to introduce a new language for the future of Apple software development.

For objective-c developers, Swift looks familiar, with the readability of objective-c named parameters and the power of the dynamic object model, providing seamless access to existing cocoa frameworks and the ability to integrate with OBJECTIVE-C. Based on this common denominator, Swift introduces many new features, a unified program, and an object-oriented language component.

Swift is friendly to the new program Ape, and as an expressive and entertaining scripting language, it is the first system programming language to get industrial quality. It supports playgrounds, a consent program ape to debug Swift code and immediately see the result without having to repeatedly compile a new function to execute the program.

Swift combines the best of modern language thinking and wisdom-from the vast Apple Project master culture. The compiler is optimized for performance and the language is optimized for development without sacrificing. Its design extends from "Hello World" to the entire operating system, making swift a meaningful investment for developers and Apple.

Swift is an excellent way to write iOS and OS X apps, and will continue to evolve with new features and functionality. Swift is ambitious and we can't wait to see what you can create with it.

2.Swift Overview

  The first program that traditionally suggests a new language should print "Hello, World" on the screen, which in Swift requires only one line to complete.

  

Assuming you've written code in C or Objective-c language, this syntax looks familiar-in swift, this line of code is a complete program, and you don't need to import a separate library for functions such as input/output or string processing. Code written on a global scale is a function entry point, so you don't need a main function, and you don't have to write a semicolon at the end of each statement.

This overview gives you enough information to start writing Swift code by showing you how to complete various program tasks . If you're not clear, don't worry, all the details in this overview will be explained later in this book.

Note: To get the best experience, open this chapter as a playground in Xcode, playground agree to edit the code list and see the results immediately.

2.1. Simple values

Using let to create a constant, VAR creates a variable . A constant value does not need to be known at compile time, but you must assign it a value once, which means you can use constants to name a value that you decide to use in many places.

  

A constant or variable must have the same type as the value that you want to assign to it. However, you do not always have to understand the type of writing. Provides a value when you create a constant or variable that allows the compiler to determine its type. In the demo example above, the compiler determines that myvariable is an integer because its initial value is an integer.

Assuming that the initial value does not provide enough information (or assuming there is no initial value), the type can be set after the change, separated by a colon.

  

Experiment: Create a constant, understood as a float type, and a value of 4

A value is never absolutely converted to another type. Suppose you need a value to be converted to a different type, to clearly create an instance of the desired type.

  

Experiment: Try to remove the string conversion from the last line, what error did you get?

Another simpler method is to include a string value: Write the value in parentheses and write a backslash (\) before the parentheses. Like what:

  

Experiment: Use (\) to include a floating-point calculation in a string and include the name of a person in a greeting.

Use square brackets ([]) to create arrays and dictionaries, and write index and key in parentheses to access their elements.

To create an empty array or dictionary, use the initialization syntax.

Assuming the type information can be judged, you can write an empty array for [] and an empty dictionary for [;]--for example, when you set a variable to a new value or a number of arguments to pass to the function.

  

Swift's new language development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.