0 Basic Learning Swift

Source: Internet
Author: User

Swift Basic Learning Chapter (i)

The swift language is a new technology released by Apple in 2014 at the WWDC (Apple Developers Conference), which is used to write iOS and OS X apps and supports code previews; Chris Lattner has been leading the development of the SWIFT programming language since July 2010;

    • Environment preparation
    • Language Features
    • Grammar Basics
    • Project Combat
Environment preparation
    • Use Xcode only to set the language to Swift;
Language features Swift's features

* 1. Run-Time Features * 

 - 速度是python的3.9倍;  (OC 速度是python的2.6倍) - 拥有自己的自动垃圾回收机制。 - 与OC共用运行时 - 可以与C、OC混合编程

* 2. Language features *

 - 闭包 - 命名空间 - 泛型 - 强类型 - 多个返回值
Features and functions of Swift
1.语法内容混合了OC、javaScript、Python,简洁方便2.新功能:闭包的统一与函数指针、元组与多个返回值3.互动娱乐4.REPL(Read_Eval_print Loop)5.专为安全6.高效强大
The simplest syntax foundation for Swift's program-->hello World
 print("hello world") 注:1.swift语言可以没有(;)分号 2.不需要主函数 3.同println自动换行
Basic data types
int Plastic Surgery
Double Floating point Type
Float Floating point Type
bool Boolean type
String String
Array Array
Dictionary Sub-code
Constants and variables declaration definition constants
let con = 100;关键字:let
Defining variables
  var avi = 30;  avi = 40;  关键字:var
One row can declare multiple constants and variables (need to be separated by "comma")
  let a = 3,b = 4,c = 5  var d = 3,e = 4,f = 5
Types of annotations
 var who:String who = "xiaoming" print(who) 注:如果给变量赋了初始值则不需要标注类型,如果没有赋初始值则需要进行类型标注
Rules for naming constants and variables

Swift language can be named with Chinese characters, letters, expressions, etc., but not in the name of numbers, arrows, lines and tabs, not by numbers.

          let 你好 = "nihao";          print(你好);          var ?? = "亲亲?(°?‵?′??)";          print(??);          var 眼睛 = "??";          
string interpolation
 var apples = 10; var orange = 4; print("i have \(apples + orange) fruits");
Comments
分为单行注释  和多行注释(可以嵌套)单行注释 // 多行注释 /*          一级注释    /*       二级注释    */ */
Type conversions
例一let f:UInt8 = 10;let g:UInt16 = 100;print("\(UInt16(f) + g)");例二let sa = 3let pi = 3.14let add = Double(sa) + piprint(add)

0 Basic Learning Swift

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.