疑问,

@interface ViewController ()

/*

    1:字符串为啥用copy?

    2:代理为啥用weak?

    3:block为啥用copy?

 */

@property (nonatomic, copy) NSString *name;

// 2:代理为啥用weak?

@property (nonatomic, strong) person *p1;

//3:block为啥用copy?

@property (nonatomic, copy) void (^myBlock)();

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

//    //创建可变字符串

//    NSMutableString *str  = [NSMutableString string];

//    //给可变字符串赋值

//    [str appendString:@"ls"];

//    //指向str地址

//    self.name = str;

//    //给可变字符串追加字符串

//    [str appendString:@"itcast"];

//    NSLog(@"%@",self.name);

    

    

    // 2:代理为啥用weak?

    //self->p1->delegate - >self循环引用

//    self.p1.delegate = self;

    

    

    

    //3:block为啥用copy?

//    //NSGlobalBlock

//    void (^test1)() = ^{

//        NSLog(@"test1");

//    };

//    NSLog(@"test1 %@",test1);

//    

////    NSStackBlock 栈区

//    int a = 7;

//    void (^test2)() = ^{

//        NSLog(@"test2 %d",a);

//    };

//    NSLog(@"test2 %@",test2);

//    

//    

//    //NSMallocBlock堆区

//    void (^test3)() = ^{

//        NSLog(@"test3 %d",a);

//    };

//    NSLog(@"test3 %@",[test3 copy]);

    

    [self demo];

    

    self.myBlock();

    

    

    

   

}

- (void)demo

{

    //实现myBlock函数

    int a = 8;

    [self setMyBlock:^{

        NSLog(@"%d",a);

    }];

//    NSLog(@"%@",self.myBlock);

}

 

posted on 2016-03-07 14:27  万紫千红红最好  阅读(125)  评论(0)    收藏  举报