objective-c 函数参数 传地址 传指针 指向指针的指针

来源:互联网 发布:javascript用有关var 编辑:程序博客网 时间:2024/05/20 18:54


传值和传址的区别,在参数get set  微妙区别  




#import "ViewController.h"


@interface ViewController ()




{

    NSMutableArray *_array;

   NSMutableArray *nextArray;

   NSData *mydata;

}


    

    

    

    

@end


@implementation ViewController

@synthesize array=_array;


- (void)viewDidLoad

{

    [superviewDidLoad];

    _array = [[NSMutableArrayalloc] initWithCapacity:4];

    

    [_array addObject:@"000"];

    nextArray = [[NSMutableArrayalloc] initWithCapacity:4];

    [nextArrayaddObject:@"002"];

    NSLog(@"_array%@",_array);

    NSLog(@"_array%p",_array);

    NSLog(@"nextArray%@",nextArray);

    NSLog(@"nextArray%p",nextArray);

    [selffoo:&_array];

    NSLog(@"_array%@",_array);

    NSLog(@"_array%p",_array);

}



-(void)foo:(NSMutableArray *__strong *) arraypointer  

//__strong:处理错误:Passing address of non-local object to __autoreleasing parameter for write-back

{

    *arraypointer =nextArray;

}



- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


原创粉丝点击