在objective-c /可可触摸有一个方便的功能找到最低的数字? [英] Is there a convenient function in objective-c / cocoa-touch to find a lowest number?
本文介绍了在objective-c /可可触摸有一个方便的功能找到最低的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数字,需要返回较低的一个。有什么功能我可以使用吗?当然这是一个容易的任务,我可以做一个if语句。
I have two numbers, and need to get returned the lower one. Is there any function I could use? Sure it's a easy task, I could do an if-statement. I just want to know.
推荐答案
如果您使用的是int,请使用 MIN / code> macro:
If you're using ints, use the MIN()
macro:
MIN(25, 50); //Returns 25
如果你比较两个 NSNumber
s,然后使用 compare:
方法:
If you're comparing two NSNumber
s, then use the compare:
method:
NSNumber *number, *secondNumber; //Assume 'number'=25, 'secondNumber'=50
NSComparisonResult result = [number compare:secondNumber];
return (result==NSOrderedDescending)?secondNumber:number; //Returns the 'number' NSNumber
这篇关于在objective-c /可可触摸有一个方便的功能找到最低的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文