随笔分类 - Swift
摘要://: Playground - noun: a place where people can play import UIKit // 值类型:指的是当一个变量赋值给另外一个变量的时候, 是copy一个副本 // 两个变量之间互不影响, 也就是说, 另外一个变量的值改变, 不会影响到另外一个变量
阅读全文
摘要://: Playground - noun: a place where people can play import UIKit // 初始化一个整数数组 var arr = [1, 3, 5, 7, 8, 10, 12, 2, 0, 11, 9] // 闭包原始模样 arr.sort(){(a:
阅读全文
摘要://: Playground - noun: a place where people can play import UIKit // 初始化一个整数数组 var arr = [1, 3, 5, 7, 8, 10, 12, 2, 0, 11, 9] // 排序, 默认是从小到大排序 arr.sor
阅读全文
摘要://: Playground - noun: a place where people can play import UIKit // 初始化一个整数数组 var arr = [1, 3, 5, 7, 8, 10, 12, 2, 0, 11, 9] // 排序, 默认是从小到大排序 arr.sor
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit/*---------------------------返回函数类型-----------------------------*/// 其实就是将函数当为返回值返回fun...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKitfunc add(a:Int, b:Int) -> Int{ return a + b}// 其中, (Int, Int) -> Int 就是显式的声明函数类型let...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit// swift中默认情况下, 传入的参数是不可以修改的, 也就是let类型, 也就是常量参数// 如果想修改这个参数的值, 需要在参数前加"var", 也就是变量参数fu...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit// 可变参数一定要放在所有定义参数的最后面, 和其他参数的定义方式一样, 只是多了3个点func add(a:Int, b:Int, others:Int...) ->I...
阅读全文
摘要:// 参数设置了默认值之后, 在调用的时候, 可以写这个参数// 在参数前面添加"_", 表示取消外部参数名, 但还是建议使用苹果默认格式func sayHello(nickName:String = "Bobo", _ greeting:String = "Hello") -> String{ ...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit// 外部参数的作用是为了让程序员调用代码的时候能清晰的看出所传参数代表的意思// 内部参数指的就是定义函数的时候所设定需要传入的参数func sayHello(nickN...
阅读全文
摘要://: Playground - noun: a place where people can play import UIKit // 定义一个数组 var userScores:[Int]? = [12, 990, 572, 3258, 9999, 1024, 666] userScores =
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit// 无参无返回// -> Void可以省略不写, 或者写成(), 因为返回值为空本质是一个空的元组func run() -> Void // (){ print("...
阅读全文
摘要://: Playground - noun: a place where people can play import UIKit // fallthrough // fallthrough会在当前case执行完之后继续下一个case // 如果在下一个case中声明了变量, 则不能使用fallth
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit// 对区间进行判断var score = 90switch score {case 0: print("You got an egg!")case 1..是介绍运算...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKitvar rating = "A"// if - else ifif rating == "A" { print("Very Good!!");} else if r...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit// for-infor i in -99...99{ i * i}let array = ["Rinpe", "Bobo", "Lili"]for (index, ...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit// 数据源let colors =[ "Air Force Blue":(red:93, green:138, blue:168), "Bittersweet...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKitvar dict = [1:"one", 2:"two", 3:"three", 4:"four"]dict.countdict.isEmptydict[1]dict[66...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKitvar str = "Hello, playground"var array = ["A", "B", "C", "D", "E", "F"]let arrayCount ...
阅读全文
摘要://: Playground - noun: a place where people can playimport UIKit// 注意: swift中的字典用的也是中括号, 和OC的大括号是不同的// 初始化字典var dict1 = [1:"one", 2:"two", 3:"three"] ...
阅读全文

浙公网安备 33010602011771号