diff --git a/Expressions-Variables-Constants.playground/Contents.swift b/Expressions-Variables-Constants.playground/Contents.swift deleted file mode 100644 index 9d86688..0000000 --- a/Expressions-Variables-Constants.playground/Contents.swift +++ /dev/null @@ -1,3 +0,0 @@ -import UIKit - -var greeting = "Hello, playground" diff --git a/Expressions-Variables-Constants.playground/contents.xcplayground b/Expressions-Variables-Constants.playground/contents.xcplayground deleted file mode 100644 index 7627317..0000000 --- a/Expressions-Variables-Constants.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Expressions-Variables-Constants.playground/playground.xcworkspace/xcuserdata/jiulinxiri.xcuserdatad/UserInterfaceState.xcuserstate b/Expressions-Variables-Constants.playground/playground.xcworkspace/xcuserdata/jiulinxiri.xcuserdatad/UserInterfaceState.xcuserstate index b376b24..f365b41 100644 Binary files a/Expressions-Variables-Constants.playground/playground.xcworkspace/xcuserdata/jiulinxiri.xcuserdatad/UserInterfaceState.xcuserstate and b/Expressions-Variables-Constants.playground/playground.xcworkspace/xcuserdata/jiulinxiri.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Expressions-Variables-Constants.playground/timeline.xctimeline b/Expressions-Variables-Constants.playground/timeline.xctimeline deleted file mode 100644 index bf468af..0000000 --- a/Expressions-Variables-Constants.playground/timeline.xctimeline +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/SwiftStudy.playground/Pages/01 注释.xcplaygroundpage/Contents.swift b/SwiftStudy.playground/Pages/01 注释.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..66d3867 --- /dev/null +++ b/SwiftStudy.playground/Pages/01 注释.xcplaygroundpage/Contents.swift @@ -0,0 +1,25 @@ +import UIKit + +// 注释的几种类型 +// 单行注释 + +/** + 多行注释 + */ + +/** + 1. + /*多行注释嵌套*/ + 2. + */ + +// 开起markdown语法,在两斜杠之后加上冒号 +//: # 一级标题 +/*: + # 学习Swift + ## 基础语法 + - 变量 + - 常量 + */ + +//: [Next](@next) diff --git a/SwiftStudy.playground/Pages/02 数据类型.xcplaygroundpage/Contents.swift b/SwiftStudy.playground/Pages/02 数据类型.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..7c83a68 --- /dev/null +++ b/SwiftStudy.playground/Pages/02 数据类型.xcplaygroundpage/Contents.swift @@ -0,0 +1,116 @@ +//: [Previous](@previous) + +//: ### 常量 +// 只能赋值一次,用let声明,它不要求在编译期间确定 +// 常量以及变量在初始化之前都不能使用 +let age: Int +age = 31 + +let name = "Zhang Mengxu" +let sex: String = "man" + + +//: ### 标识符 +// 标识符(比如常量名、变量名、函数名)几乎可以使用任何字符 +// 标识符不能以数字开头,不能包含空白字符、制表符、箭头等特殊字符 + +//: ### 常见的数据类型 +/*: + 常见的数据类型: + - 值类型(value type) + - 引用类型(reference type) + + 值类型(value type) + 值类型包含: + - 枚举(enum): + Optional + - 结构体(struct): + Bool、Int、Float、Double、Character、String、Array、Dictionary、Set + + 引用类型(reference type) + 引用类型包含: + - 类(class) + */ + +//: #### 整数类型 +/*: + 整数类型:Int8、 Int16、 Int32、 Int64、 UInt8、 UInt16、 UInt32、 UInt64 + 在32bit平台,Int等价于Int32, Int等价于Int64 + 整数的最值:UInt8.max、 Int16.min + 一般情况下,都是直接使用Int即可 + */ +let a:Int = 10 +print(Int.max) + + +//: #### 浮点类型 +/*: + 浮点类型:Float,32位,精度只有6位Double,64位,精度至少15位 + */ +let letFloat:Float = 30.0 +let letDouble:Double = 30.0 + +//: #### 字面量 +// 布尔值 +let bool = true + +// 字符串 +let string = "Zhang Mengxu" + +// 字符 +let character: Character = "🐶" + +// 整数 +let intDecimal = 17 // 十进制 +let intBinary = 0b1001 // 二进制 +let intOctal = 0o21 // 八进制 +let intHexadecimal = 0x11 // 十六进制 + +// 浮点数 +let doubleDecimal = 125.0 // 十进制,等价于1.25e2、 0.0125、 1.25e-2 +let doubleHexadecimal1 = 0xFp2 //十六进制,意味着15x2^2,相当于十进制的60.0 +let doubleHexadecimal2 = 0xFp-2 // 十六进制,意味着15x2^-2,相当于十进制的3.75 + +// 数组 +let array = [1, 3, 5, 7] + +// 字典 +let dictionary = ["name": 34, "age": 18] + +//: #### 类型转换 +// 整数转换 +let int1: UInt16 = 2_000 +let int2: UInt8 = 1 +let int3 = int1 + UInt16(int2) + +// 整数浮点数转换 +let int = 3 +let double = 0.14159 +let pi = Double(int) + double +let intpi = Int(pi) + +//: #### 元组(tuple) +// 元组的定义 +let httpError = (404, "Not Found") + +// 元组访问 +httpError.0 +httpError.1 +print("The status code is \(httpError.0)") + +// 元组的赋值 +let (statusCode, statusMessage) = httpError +print("The status message is \(httpError.1)") + +// -代表的是不接收参数值,Not Found会忽略 +let (justTheStatusCode, _) = httpError + +// 元组中添加参数,使用的时候通过名称访问,而非数字 +let http200Status = (statusCode: 200, description: "ok") +print("The status code is \(http200Status.statusCode)") + + + + + +//: [Next](@next) diff --git a/SwiftStudy.playground/contents.xcplayground b/SwiftStudy.playground/contents.xcplayground new file mode 100644 index 0000000..96638d2 --- /dev/null +++ b/SwiftStudy.playground/contents.xcplayground @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/SwiftStudy.playground/playground.xcworkspace/contents.xcworkspacedata b/SwiftStudy.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/SwiftStudy.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/SwiftStudy.playground/playground.xcworkspace/xcuserdata/jiulinxiri.xcuserdatad/UserInterfaceState.xcuserstate b/SwiftStudy.playground/playground.xcworkspace/xcuserdata/jiulinxiri.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..fd5f43c Binary files /dev/null and b/SwiftStudy.playground/playground.xcworkspace/xcuserdata/jiulinxiri.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SwiftStudy.playground/xcuserdata/jiulinxiri.xcuserdatad/xcschemes/xcschememanagement.plist b/SwiftStudy.playground/xcuserdata/jiulinxiri.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..31bc51b --- /dev/null +++ b/SwiftStudy.playground/xcuserdata/jiulinxiri.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,16 @@ + + + + + SchemeUserState + + SwiftStudy (Playground).xcscheme + + isShown + + orderHint + 0 + + + +