How would you define a simple “min” method in obj-c

前端 未结 7 2211
感动是毒
感动是毒 2020-12-16 11:42

I want to define a min and max methods in a Utils class.

@interface Utils

int min(int a, int b);
int max(int a, int b);

@end

But I don\'t

相关标签:
7条回答
  • 2020-12-16 12:23

    Objective-C class methods use named parameters, period. That's just the way it is.

    Why not make it a global, free function? You shouldn't need a Utils class for this kind of thing.

    If you don't want to clutter the global namespace, you could use Objective-C++ (rename all .m files to .mm) and put it in a namespace.

    0 讨论(0)
提交回复
热议问题