Function taking a variable number of arguments

前端 未结 2 903
忘了有多久
忘了有多久 2021-02-07 02:32

In this document: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html#//apple_ref/doc/uid/TP40014097-CH2

2条回答
  •  爱一瞬间的悲伤
    2021-02-07 02:58

    In case of all arguments are Int numbers: Int[] would be intuitive. But if you have code like this:

    func foo(args:AnyObject...) {
        for arg: AnyObject in args {
            println(arg)
        }
    }
    
    foo(5, "bar", NSView())
    

    output:

    5
    bar
    
    

提交回复
热议问题