本文介绍了与MIN和MAX宏相同的Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C / Objective-C中,使用MIN和MAX宏可以找到两个数字之间的最小值和最大值。 Swift不支持宏,并且在语言/基础库中似乎没有等价物。是否应该使用自定义解决方案,可能是基于这种一的泛型? p> 解决方案 请参阅记录&在Swift中没有记录的内置函数。
min 和 max
func maxIn C / Objective-C it is possible to find the minimum and maximum value between two numbers using MIN and MAX macros. Swift doesn't support macros and it seems that there are no equivalents in the language / base library. Should one go with a custom solution, maybe based on generics like this one?
解决方案min and max are already defined in Swift:
func max<T : Comparable>(x: T, y: T, rest: T...) -> T func min<T : Comparable>(x: T, y: T, rest: T...) -> TSee this great writeup on documented & undocumented built-in functions in Swift.
更多推荐
与MIN和MAX宏相同的Swift
发布评论