swift 函数参数可选_Swift中的可变参数函数

本文介绍了Swift编程语言中关于函数参数可选的特性,特别是可变参数函数的使用方法。通过翻译自Medium的文章,读者将理解如何在Swift中定义和调用可变参数函数。
摘要由CSDN通过智能技术生成

swift 函数参数可选

A variadic function is simply a function that accepts 0 or more items of the same type.

可变参数函数只是接受0个或多个相同类型项的函数。

What uses variadic functions?

什么使用可变参数功能?

If you have ever used the print statement then you have used variadic function. If we click into it’s signature, then we get the following

如果您曾经使用过print语句,那么您已经使用了可变参数函数。 如果单击它的签名,则会得到以下内容

public func print(_ items: Any..., separator: String = " ", terminator: String = "\n")

The print function accepts any amount of items that are of type Any. Which allows us to print multiple object by separating them with a comma.

打印功能接受任何类型的任何项目。 这允许我们通过用逗号分隔多个对象来打印它们。

Let’s make our own variadic function

让我们

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值