请说出NSLog输出的内容
NSString *name1 = [NSString stringWithFormat:@"CoderZNBmm"];
__weak NSString *name2 = name1;
NSLog(@"name1:%@", name1);
NSLog(@"name2:%@", name2);
name1 = nil;
NSLog(@"name1:%@", name1);
NSLog(@"name2:%@", name2);
NSString *a1 = [[NSString alloc] initWithFormat:@"CoderZNBmm"];
__weak NSString *a2 = a1;
NSLog(@"a1:%@", a1);
NSLog(@"a2:%@", a2);
a1 = nil;
NSLog(@"a1:%@", a1);
NSLog(@"a2:%@", a2);
NSString *b1 = @"CoderZNBmm";
__weak NSString *b2 = b1;
NSLog(@"b1:%@", b1);
NSLog(@"b2:%@", b2);
b1 = nil;
NSLog(@"b1:%@", b1);
NSLog(@"b2:%@", b2);
当把__weak 换成 __strong 后结果又是怎样
再看看下面的情况
NSObject *obj1=[[NSObject alloc] init];
__strong NSObject *obj2 = obj1;
NSLog(@"%@,%@", obj1, obj2);
obj1 = nil;
NSLog(@"%@,%@", obj1, obj2);
NSObject *obj3=[[NSObject alloc] init];
__weak NSObject *obj4 = obj3;
NSLog(@"%@,%@", obj3, obj4);
obj3 = nil;
NSLog(@"%@,%@", obj3, obj4);
我当时一脸懵逼,心想其中肯定有诈.怎么办呢...
@@@
@@@
几分钟后,结果被玩坏了.😂
网友评论