直接上代码
//: Playground - noun: a place where people can play
import UIKit
var number = 123
var str = "this \(number)"//输出字符串
let ? = "123"
let testInt : Int = 1
let testDouble = 1.1
let testFloat = 1.111
Int.max
UInt8.max
UInt16.max
UInt32.max
UInt64.max
//不同类型不能混合运算需要转
? + String(123)
//使用 typealias 定义别名不同于oc的 typedef
typealias SSS = String
let alias : SSS = "子非鱼"
//新增范围运算符/溢出运算符
for item in 0...8
{
print(item)
}
for item in 10..<13
{
print(item)
}
//溢出运算符只能用于整形 &+ &- &* &/
var aa = Int.max
var bb = 1
var cc = aa &+ bb
cc == Int.min
//元组类型
var ary = (a:1001 ,b:"2001 HelloWorld",c:3001)
ary.a
ary.b
ary.c = 3002
ary.0 + 1
//流程控制 新增for in , 可以使用group标签 如下 for1
for1:for _ in 1...3
{
for i in 1...3
{
print("helloworld \(i)")
break for1
}
print("!!!!!!")
}
//switch 不需要写break,执行完一个case就反回了
//每一个case后面必须要写点可以运行的代码
var ttt = "1"
switchttt
{
case"1","3","4":
print(" 1 3 4 ++++")
case "2":
print("123123123")
default:
print("default")
}
//使用范围运算符
var aaaa = 1
switchaaaa
{
case 1,2,3,4:
print(" 1 3 4 ++++")
case 90...100:
print("123123123")
default:
print("default")
}
//使用元组
var point = (10,10086)
switchpoint
{
case (_,var y) where y == 10086:
print("0,\(y)")
fallthrough//贯穿一层case 只要不定义变量就可以穿。。。
case(5...10,10086):
print("10,10")
default:
print("default")
}
//function
func test(num:Int)->String
{
if(num == 1)
{
return "Helloword\(num)";
}
return "";
}
func test2(var str:String = "**********")
{
str = "qwe";
print("Helloword \(str)")
}
func test3(user_name name:String,_ user_age:Int)->(name:String,age: Int)
{
return (name,66666);
}
func test4(inout num :Int)
{
num = 10
}
var num:Int = 20
test4(&number)
test3(user_name: "肖念", 21)
test2()