10.4NSNumber 装箱

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    //C的写法,默认后面有\0, 我们说长度就是数到\0为止, 说占多少内存就是说有多少个字符

    char *s =  "hello \0world";

    //OC的写法

    NSString *ss = @"welcome";

   
    int a  = 11;
    float b = 12.3;
    double c = 22.44;
    
    //NSNumber就是集合了int,float,double

    NSNumber *num = @(a);

    NSNumber *num2 = @(b);//装箱
   
 
    CGRect rect = CGRectMake(100, 100, 100, 100);
    
    [NSValue valueWithCGRect:rect];
    
    CGPoint point = CGPointMake(100, 100);
    
    NSValue *pointValue = [NSValue valueWithCGPoint:point];
    
  @[pointValue];
    
    NSLog(@"%@",[NSValue valueWithCGRect:rect]);

    //直接转为字符串,动态的调用,还可以转CLASS,SEL等。从服务器上面拿下来以后转,方便

    NSLog(@"-->%@",NSStringFromCGRect(rect));
    
    //OC的方法调用
    [self demoFunc:11 andB:23];
    NSLog(@"%@",[self class]);
    
    //用C写的方法调用,看上去比较干净
    demoFunc2(11,22);

}

- (void)demoFunc:(NSInteger)a andB:(NSInteger)b{

}

//用C写的方法,用C写的话看上去比较干净
void demoFunc2(int a,int b){
   
}

@end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容