<html>

Source: Internet
Author: User

Written in front: the content of the study is mainly from "the Swift programming Language". You can download it in itunes as part of the translation content and understanding. Due to limited English proficiency, part of the Google translation

Gossip Less, open the whole:


Hello World (Getting started)

All the programs have just started to write Hello world. In Swift, so to write

println ("Hello, World")
Note: The new feature, one that is sufficient, does not need to import input/output or string processing functions of the library. There is no need for the main function, not even the end of the semicolon

The article also mentions what Xcode has to add: Playground, writing code in the playground. The ability to see execution results directly without the need for compilation. Save time and improve efficiency. BlaBla


Simple Values (basic data types)

Use let to define a constant, use Var to define a variable

var myvariable = 42myVariable = 50let Myconstant = 42
Note: new features. The compiler determines the type of constant or variable, as in the above code, the compiler determines that myvariable is shaping, because the initial value is a shape (a bit like JS)


Suppose the initial value does not provide enough information to infer the type (or no initial value). Want to specify the type of variable or constant swollen? ——— add a type after a constant or variable and separate it with a colon

Let Implicitinteger = 70let implicitdouble = 70.0let explicitdouble:double = 70

Other than that. The type of the value does not have to be self-loading, which means that you still need to use type conversion (no conversion will be an error.) This is not necessary, for example, using string (9) to convert a shape to a string type

Let label = ' the width is ' let width = 94let widthlabel = label + String (width)

Another way to put a variable or constant in a string. Put the variable in parentheses (), preceded by a backslash \, such as \ (variable. constant)

Let apples = 3let oranges = 5let applesummary = "I has \ (apples) apples." Let fruitsummary = "I has \ (apples + oranges) pieces of fruit.

Use brackets [] to define an array or dictionary, with the following proportions:

var shoppinglist = ["Catfish", "water", "tulips", "Blue paint"]shoppinglist[1] = "bottle of water" var occupations = [
   
     "Malcolm": "Captain",    "Kaylee": "Mechanic",     "Jayne": "WTF"]
   
occupations["Jayne"] = "public relations

Initializes an empty array or dictionary:

Let Emptyarray = string[] () Let emptydictionary = Dictionary<string, float> ()

To define an empty array or dictionary:


In the next section we'll talk about conditional statements in the basics.

Read the full text of the copyright notice: This article for Bo Master original article, without Bo Master agreed not to reprint. Report
    • Label:
    • Q=swift&t=blog "target=" _blank ">swift /

    • Xcode /
    • q= basic &t=blog "target=" _blank "> base /

    • Swift Foundation /
    • This article has been included in the following column:
    • Swift Learning Basics
1Article comments
Related articles recommended
Swift Learning Notes (iv)--a tuple of advanced data types specific explanation tuples as an advanced data type are not in many other languages. There is no concept of tuples in java,c,c++. In Python, there is a concept of tuples. So it's relatively special. We'll have a good study.

?????? Tuples (meta-group) ...

  • CHENYUFENG1991
  • 2015-07-26 15:45
  • 960
Swift0 Basics: Variables and data types//: Playground-noun:a place where peop Le can playimport uikit//1. First program var str = "Hello, playground" println ("hello,swift!") 2.let constant constants, var variable variableslet websitename:string = "www.baidu.com" var integer: Int = 10let bignum_a = 1000000let Bignu M_b = 1_000
  • Adoudou not amumu
  • 2015-09- 20:03
/dl>
Learning Swift from scratch (day 11)-Data type What's the matter? Original articles, welcome reprint. Reprint Please specify: Dongsheng's blog?? When we learn languages, we learn the data types of such languages, what are the types of data in Swift? Integer, float, Boolean, character, string these types are certain, in which collections, enumerations, structures ...
  • Tonny_guan
  • 2015-09-11 10:00
  • 1808
Learn notes from the zero-learning Swift (day 13)-data type integer and floating-point Swift 2.0 Learning notes (<span lang=)
  • Dongsheng
  • 2015-09-16 14:01
  • 319
Learn notes from the zero-learning Swift (day 13)-integer and floating-point types of data type provide signed and unsigned integers in 8, 16, 32, 64-bit form. These integer types follow the naming conventions of the C language. I summed up the integral type in Swift:?...
  • Yidu_blog
  • 2016-08-23 16:55
  • 69
Learn
notes from the zero-learning Swift (DAY48)--type check and convert Swift 2.0 learning notes (day48</sp
  • Dongsheng
  • 2015-12-14 11:11
  • 214
learning Swift from scratch (day 13)--data type integer and floating-point original articles, welcome reprint.

Reprint Please specify: Dongsheng's blog???????????? Swift provides signed and unsigned integers in 8, 16, 32, 64-bit form. These integer types follow the naming conventions of the C language, and I summarize the integral types in swift:?...

  • tonny_guan
  • 2015-09-16 13:47
  • 1775
The matching inference instance code for different data types in switch in Swift is as follows [code= "Swift"]var things = any[] () things.append (0) things.append (0.0) things.append Things.append (3.14159) things.append ("Hello") Things.append ((3.0, 5.0)) Things.append (Movie (name: "Ghostbusters ", Director:" Ivan Reitman "))) for thing in things {switch thing {
  • Liyunpeng
  • 2014-06-12 15:54
  • 3338
Learning Swift from scratch (day 11)-Data type What's the matter? Original article. Welcome reprint. Reprint Please specify: Dongsheng's blog <span
  • Dongsheng
  • 2015-09-11 10:08
  • 70
swift--data type definition constants Let Ci1 = 1let Ci2:int = 2let CD1 = 1.2let Cd2:double = 2.3 must initialize the type to be able to judge by the right value, also can explicitly specify the type variable ...
  • Mardax
  • 2016-02-16 17:29
  • 66
on the code body. Heart to Fly + concern
Original
231
Fans
-
Like
0
    • JSB Development 10
    • JSB Development 9
    • JSB Development 8
    • JSB Development 7
many other articles Online Courses

Utm_source=blog7 "target=" _blank ">" Live "Machine learning & Data Mining 7 weeks training--Wei Chi

Utm_source=blog7 "target=" _blank ">" Package "System integration project manager Smooth customs clearance--Xu Bong

  • folder
  • like to cancel like
  • Collection
  • share Weibo QQ
Collection Assistant Bad news report

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.