[Swift] Basics

Source: Internet
Author: User

[Swift] Basics

One, common variables

var str = "Hello, playground"//variable let str1= "Hello xmj112288"//constant//multivariable, note; And, the difference var int1:int32; var str2:string;var int2:int32, Str3:stringvar f1:float=0.1,d1:double=2.1,s1:string= "S1"; Display definition type var char:character = "1"//char definition var num=100000000var num1=100_000_000//digital good-looking definition way var t1= ("XMJ")//Ganso T1. 0t1.1var t2= (age:18,name: "XMJ") t2.aget2.namevar arr1:array<string> = ["1", "2", "3"]//array var dic1:dictionary< string,int32> = ["1": 1, "2": 2]//dictionary func Add (var a:int32,inout b:int32, C:int32 = 3), Int32//function, a without var definition is often InOut reference parameter {a = a+1 B = b+1 return a+b;} var b:int32=5add (1, B: &b)//& reference parameter var ADD1 = Add//function as a variable, note that the parameter with default value becomes without default value such as CADD1 (2,b:&b,c:3) enum E  Num1:int32//enum {case E1,e2,e3,e4}var set:set<int32> = [1,2,3,4,4,5,4,3,2]//similar to C # HashSet 

var n:int32? Nullable type
var n1 = n!//Gets the value of a nullable type, note that an error   when empty;

var q1 = 0...5//Interval
var q2 = 0..<5

[Swift] Basics

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.