weak ...
:
@interface ObjectWithStrongRef : NSObject
@property (strong) NSString *ref;
@end
@interface ObjectWithWeakRef : NSObject
@property (weak) NSString *ref;
@end
ObjectWithWeakRef , , ObjectWithStrongRef, ref , , ref , ref .
int main(int argc, const char * argv[]) {
ObjectWithWeakRef *weak = [[ObjectWithWeakRef alloc] init];
@autoreleasepool {
ObjectWithStrongRef *strong = [[ObjectWithStrongRef alloc] init];
strong.ref = [NSString stringWithFormat:@"Hello %@", @"World"];
weak.ref = strong.ref;
NSLog(@"Weak.Ref = %@", weak.ref);
}
NSLog(@"Weak.Ref = %@", weak.ref);
}
, ref . Objective-C , , stringWithFormat:, .
NSLog strong.ref , , weak.ref, , "Hello World".
NSLog @autoreleasepool, strong, ( NSLog ObjectWithStrongRef dealloc d . ). strong , @autoreleasepool, - , , - weak , ( , strong ).
, NSLog Weak.Ref = (null).