i declare two properties on header file:
@property(strong)NSString *p1;
@property(assign)NSString *p4;
now on implementation file, i write two method to test assign property:
- (void)testAssign {
NSString *rawString = @"Hello, ";
NSString *resultString = [rawString stringByAppendingString:@"World"];
self.p4 = resultString;
resultString = nil;
(@"My group is %@", self.p4);
}
On this scene will be an error.
but when the code as below , this do well:
- (void)testString {
NSString *rawString = @"Hello, ";
NSString *resultString = [rawString stringByAppendingString:@"World"];
self.p4 = resultString;
self.p1 = resultString;
NSLog(@"now result is %@, %@", self.p4, self.p1);
resultString = nil;
NSLog(@"now result is %@, %@", self.p4, self.p1);
self.p1 = nil;
NSLog(@"now result is %@, %@", self.p4, self.p1);
}
the result is :
2014-06-29 19:10:55.798 TestDemo[20853:303] now result is Hello, World, Hello, World
2014-06-29 19:10:55.798 TestDemo[20853:303] now result is Hello, World, Hello, World
2014-06-29 19:10:55.799 TestDemo[20853:303] now result is Hello, World, (null)
what happen on the second snippet? why is there no error?