http://blog.csdn.net/lzx_322/article/details/28861199

swift 函数使用前面需要添加 func 有返回值需要使用-> 后面添加返回类型 ,很容易理解,在看英文版的pdf文档时候看到嵌套函数的返回值,刚开始没有太明白,仔细思考了一会还是很容易理解的:

例如:func stepBackward(input: Int) -> Int {
return input - 1
}

返回值是int型的。

func chooseStepFunction(backwards: Bool) -> (Int) -> Int {
func stepForward(input: Int) -> Int { return input + 1 }
func stepBackward(input: Int) -> Int { return input - 1 }
return backwards ? stepBackward : stepForward
}

这里的  chooseStepFunction 返回值类型是(Int) -> Int,看函数中的return 是函数 stepBackward or stepForward,这两个函数的类型正是(Int) -> Int。最终返回的数值是还是int型。

再例如:

func testFunction(a:int,b:int)->(int,int)->int{

func getFunction(a:int,b:int)->int{

return a-b

}

return getFunction

}

外面的函数返回的是(int,int)->int,恰好返回是嵌套里面面的函数,此函数最终返回的是嵌套里面函数的返回值。这是我对嵌套返回的理解,表述不是很清晰,希望对大家有所帮助,不足之处欢迎指出。

版权声明:本文为博主原创文章,未经博主允许不得转载。

swift 之嵌套的理解 func chooseStepFunction(backwards: Bool) -> (Int) -> Int的更多相关文章

  1. swift 闭包+嵌套函数+extension+单例+嵌套函数+??

    //: Playground - noun: a place where people can play import UIKit //*******************嵌套函数********* ...

  2. 如何理解这段代码:void (*signal (int sinno,void(*func)(int)))(int)

    void (*signal (int sinno,void(*func)(int)))(int) 先来看void(*func)(int)   这里的意思是声明一个函数指针func,它的参数类型为int ...

  3. [Swift]LeetCode339. 嵌套链表权重和 $ Nested List Weight Sum

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

  4. void (*signal(int sig, void (*func) (int))) (int)理解

    http://blog.csdn.net/sever2012/article/details/8281271 1.signal( int sig, void (*func)(int))signal是一 ...

  5. signal函数理解或者void (*signal(int signum,void(*handler)(int)))(int)理解

    把void (*signal(int signum,void(*handler)(int)))(int)分成两部分: typedef void (*sighandler_t)(int); sighan ...

  6. C# 泛型 Func<object, string, bool> filter

    Func<object, string, bool>是泛型,你可以先把他看成一个普通类型,比如stringpublic class Func{ } // 自定义个普通类. Func fil ...

  7. Swift -> Optional嵌套 探讨

    准备运动:Optional 的介绍 王巍的<Swifter>一书中,介绍了一个有用的命令:在 LLDB 中输入 fr v -R foo,可以查看foo 这个变量的内存构成.我们稍后的分析将 ...

  8. Swift 类型嵌套

    1.类型嵌套 Swift 支持类型嵌套,把需要嵌套的类型的定义写在被嵌套的类型的 {} 中. Swift 中的枚举类型可以辅助实现特定的类或者结构体的功能. struct SchoolUniform ...

  9. Swift - 类型嵌套(以扑克牌结构体为例)

    类型嵌套,简单来说实在一个类型中包含另外一个类型.我们拿一副扑克来说明. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 //类 ...

随机推荐

  1. LAMP架构应用实战—Apache服务介绍与安装01

    LAMP架构应用实战—Apache服务介绍与安装01   一:Apache是什么 Apache是Apache基金会开发的一个高性能.功能强大.安全可靠.灵活的开放源码的WEB服务软件 二:Apache ...

  2. 6.爬虫 requests库讲解 总结

    requests库的总结: 用ProcessOn根据前面的几节内容做了个思维导图:

  3. Python 学习笔记之 Numpy 库——文件操作

    1. 读写 txt 文件 a = list(range(0, 100)) a = np.array(a) # a.dtype = np.int64 np.savetxt("filename. ...

  4. jira+mysql+破解+中文+compose

    1.制作docker-compose.yml 2.安装 $ docker stack deploy -c docker-compose.yml mshk_jira

  5. HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)

    Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...

  6. 安装CentOS 5.x与多重引导小技巧

    不建议使用Virtualbox安装Linux来学习!本处是学习在计算机上安装Linux. 但现在条件有限,就先使用Virtualbox练习!

  7. truffle开发一个简单的Dapp

    1.安装Truffle:npm install -g truffle 2.建立项目目录并进入:mkdir pet-shop-tutorial cd pet-shop-tutorial 3.使用truf ...

  8. java线程(4)——线程同步的锁技术

    同步 同步,字面来看,有点一起工作的意思.但在线程同步中,"同"意为协同.互相配合. 比如: A.B两个线程,并不是说两个线程必须同时一起工作,而是说互相配合工作,在某个时间可能线 ...

  9. HL7 2.6 解析(XML)

    用途:检验化验(LIS)实验室设备数据交换解析. using System; using System.Collections.Generic; using System.Text; using Sy ...

  10. js阻止冒泡事件和默认事件的方法

    阻止默认事件 function stopDeFault(e){ if(e&&e.preventDefault){//非IE e.preventDefault(); }else{//IE ...