开发中const使用场景
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
/*
const开发中使用场景
// 1.定义一个全局只读变量
// 2.在方法中定义只读参数
*/
NSString * const name = @"123";
// 修饰对象
- (void)test:(NSString * const)name
{
}
// 修饰基本变量
- (void)test1:(int const)a
{
// a = 3;
}
// 修饰指针变量
- (void)test2:(int const *)p
{
// *p = 2;
NSLog(@"%d",*p);
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self test:@"123"];
[self test1:2];
int a = 10;
[self test2:&a];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end```
本文标题:开发中const使用场景
本文链接:https://www.haomeiwen.com/subject/lebmdttx.html
网友评论