swift day2

for in循环

for number in 1...100{
print(number)
}

Nested function 嵌套函数

typealias op = (Int) -> Int

func whichOne(n: Bool) -> op{
    func increment(n: Int) -> Int{
        return n + 1
    }
func whichOne(n: Bool) -> op{
    func decrement(n: Int) -> Int{
        return n - 1
        
    return n ? increment : decrement    
    }   
    
}
//typealias 是对已经存在的类型进行别名设置 typealias op = (Int)

Closure

{( param list) -> RetType in

  /*Closure body*/
  
}

scope用来定义编程语言中的各种实体(例如变量/函数/常量等等)
在哪个范围里可以被访问,在离开作用域后,就不能被访问了.

optional

if converResult != nil{
//Force unwrapping 强制解包
    print(converResult!)
}

optional binding // optional绑定

if let number = converResult{
    number++
    print(number)
    print(converResult)
)else{
 print(""Convert result is nil)
}

隐式解包 自动去获取optional的值

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容