【发布时间】:2019-01-23 00:55:57
【问题描述】:
我怎样才能使用户只能传递特定值的方法,例如
button.setTitle("SKIP", for: .normal)
setTitle 方法在 "for" 后面接受特定参数,我们只需按 。 (点)并显示要传递的值的建议。
我想做同样的事情,例如我想做一个计算两点之间距离的方法,
func distanceBetween(loc1: CLLocation, and loc2: CLLocation, unit: String) -> CLLocationDistance {}
这里用户将位置1和位置2作为参数传递,我想在他传递单位时限制用户,他应该只有3个选项,公里,英里和米。
【问题讨论】:
-
enum是您所需要的。 -
请您分享指导我方向的代码 sn-p 或任何有示例的教程。
标签: ios methods parameter-passing swift4