ios - swift 元组 ,闭包 的一些问题?
ringa_lee
ringa_lee 2017-04-18 09:51:24
0
1
408
class TTTTT {
    
    var mothod1: (String, String) -> Array<String> {
        
        return {
            [$0.0,$0.1]
        }
    }
    
    var mothod2: (String) -> Array<String> {
        
        return {
            [$0]
        }
    }
}
let test = TTTTT()
test.mothod1("s", "sss")
test.mothod2("ssa")

这段代码如何理解,

  1. mothod1是方法么?

  2. mothod1的参数是元组?

  3. mothod2的参数是一个字符串?

  4. 这种写法有什么优势?

  5. 这是方法作为属性么?

下面这样写为啥不行

研究了一会,

  1. 是闭包类型的变量

  2. mothod1的参数是元组
    原因:

  1. mothod1, mothod2应该是闭包类型

ringa_lee
ringa_lee

ringa_lee

reply all(1)
Peter_Zhu

Mothod1 and method2 are both computed properties. That is to say, the code in the closure will be run every time it is called. So this feature can be used to dynamically calculate results.
var mothod1: The following are all parameters {
means that the type of mothod1 variable is pass in the closure of the tuple and return the array
Right. The word is spelled wrong. method . . . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!