Reputation: 2217
Whats the difference between NSString and NSURL on __weak ?
My example:
__weak NSURL *myURL = [NSURL fileURLWithPath:@"/tmp"];
__weak NSString *myString = @"123";
NSLog(@"myURL: %@", myURL);
NSLog(@"myString: %@", myString);
The result:
2012-07-10 19:23:49.858 myApp[56093:303] myURL: (null)
2012-07-10 19:23:49.859 myApp[56093:303] myString: 123
Why isn't the result myString == (null)
Upvotes: 1
Views: 93
Reputation: 138
Try this
NSLog(@"myURL: %@", [myURL description]);
NSLog(@"myString: %@", myString);
As "%@" is used to represent NSString not NSURL.
Upvotes: -1
Reputation: 56625
This is because the string in your example is a string literal that never gets released. Your property doesn't retain the string but since it doesn't get released it still points to the value you assigned it.
If you would have created the string using [NSString stringWithFormat:@"hello"];
then you would see the expected behavior.
Upvotes: 6