Breaking News
Home / iOS / ObjectiveC / How to find min and max of two values in ObjectiveC?

How to find min and max of two values in ObjectiveC?

Answer

The MIN and MAX of two values is defined as a macro in NSObjCRuntime.h as

#if !defined(MIN)
    #define MIN(A,B)((A) < (B) ? (A) : (B))
#endif

#if !defined(MAX)
    #define MAX(A,B)((A) > (B) ? (A) : (B))
#endif

So in order to find MIN of X and Y use

   int num = MIN(X,Y);

to find MAX of X and Y use  

int num = MAX(X,Y);

[pb_builder]

Check Also

Singleton Example in Objective C?

Solution static MyManager *sharedManager = nil; +(MyManager*) sharedManager {         if (sharedManager == nil)         …

Advertisment ad adsense adlogger