
swift
m714星云
渣渣
展开
-
swift 闭包
类似于python中的lambda函数(匿名函数)语句格式:{ (parameters) -> return type in statements}最初的函数格式:func backward(_ s1: String, _s2: Strin) -> Bool { return s1 > s2}var reverseNames = names.sorted(by: backward)改写成闭包格式:reverseNames = names.sorted(by: {原创 2020-05-23 21:11:03 · 247 阅读 · 0 评论 -
swift函数
函数类型:参数类型和函数返回值共同组成使用方法:使用函数类型:将一个恰当的函数赋值给一个类型为函数的变量或常量var mathFunction: (Int, Int) -> Int = addTwoIntslet anotherMathFunction = addTwoInts//与mathFunction一样使用:mathFunction(2, 3)类型为函数的变量也可以像普通变量一样进行赋值函数类型可以作为参数传给函数func printMathresult(_ mathFunct原创 2020-05-22 16:41:33 · 166 阅读 · 0 评论 -
swift 集合
集合:无序的,唯一的(distinct & unordered)Swift的集合没有简单缩写,只能写成Set<element>集合可以用[]清空 声明:var favouriteGenres: Set = ["Rock", "Classical", "Hip Hop"]一些用法:查询个数:favouriteGenres.count判断是否为空:favouriteGenres.isEmpty插入:favouriteGenres.insert(" ")az删除:favouri原创 2020-05-22 16:41:06 · 352 阅读 · 0 评论 -
swift programming languag 笔记
swift数据类型IntDoubleFloatStringBoolOptional集合类型ArraySetDictionaryTuple常量与变量let声明常量,var声明变量常量的值一旦确定就不能更改了var的willset, didset用法var KittyMoney = 0 { willSet {//在这个值被修改前调用 print("Original Money: \(KittyMoney)") } didSet {/原创 2020-05-17 21:08:45 · 1168 阅读 · 0 评论 -
swift 闭包
闭包形式{ (<#parameters#>) -> <#return type#> in <#statements#>}原创 2020-05-10 15:17:20 · 206 阅读 · 0 评论 -
swift函数
函数的形式func <#name#>(<#parameters#>) -> <#return type#> { <#function body#>}"_"表示函数条用的时候,忽略参数名称func plus(_ a: Int, b: Int) { print( a+b )}plus(1, b: 2)形参加and,也可以忽略掉参数名称func plus1(_ a: Int, and b: Int) { p原创 2020-05-10 15:16:29 · 163 阅读 · 0 评论