首页 > 代码库 > Objective-C - 类的静态常量

Objective-C - 类的静态常量

创建头文件(.h), 导出常量:

// Constants.h
FOUNDATION_EXPORT NSString *const MyFirstConstant;
FOUNDATION_EXPORT NSString *const MySecondConstant;
//etc.

(代码不用于C/C++混合编程时, 能够使用extern取代FOUNDATION_EXPORT.)

定义源文件(.m), 设置常量:

// Constants.m
NSString *const MyFirstConstant = @"FirstConstant";
NSString *const MySecondConstant = @"SecondConstant";
//etc.

使用类常量时, 须要引入头文件(.h).


技术分享

<script type="text/javascript"> $(function () { $(‘pre.prettyprint code‘).each(function () { var lines = $(this).text().split(‘\n‘).length; var $numbering = $(‘
    ‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>

Objective-C - 类的静态常量