I have seen all those links which you have mentioned, But I am not fully understand from that, I am looking a programmatic example for my understanding, that why I use the above program for copy and strong which I have understand bit, but i want to know about strong,retain and weak.
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property(strong,nonatomic)NSString*name;
@end
@implementation Person
@synthesize name;
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *obj = [[Person alloc]init];
//Class method not need to create object
NSMutableString *name1=[[NSMutableString
alloc]initWithString:@"kkk"];
// Instance Method need to create object
[obj setName:name1];
NSLog(@"%@",[obj name]);
[name1 appendString:@" is Lazy"];
NSLog(@"%@",[obj name]);
}
return 0;
}
2016-03-23 17:33:28.997 Copy&Strong[7225:303] kkk
2016-03-23 17:33:29.006 Copy&Strong[7225:303] kkk is Lazy
// ************************************************************************
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property(retain,nonatomic)NSString*name;
@end
@implementation Person
@synthesize name;
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *obj = [[Person alloc]init];
//Class method not need to create object
NSMutableString *name1=[[NSMutableString
alloc]initWithString:@"kkk"];
// Instance Method need to create object
[obj setName:name1];
NSLog(@"%@",[obj name]);
[name1 appendString:@" is Lazy"];
NSLog(@"%@",[obj name]);
}
return 0;
}
2016-03-23 17:33:28.997 Copy&Strong[7225:303] kkk
2016-03-23 17:33:29.006 Copy&Strong[7225:303] kkk is Lazy
//**************************************************************************
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property(weak,nonatomic)NSString*name;
@end
@implementation Person
@synthesize name;
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *obj = [[Person alloc]init];
//Class method not need to create object
NSMutableString *name1=[[NSMutableString
alloc]initWithString:@"kkk"];
// Instance Method need to create object
[obj setName:name1];
NSLog(@"%@",[obj name]);
[name1 appendString:@" is Lazy"];
NSLog(@"%@",[obj name]);
}
return 0;
}
2016-03-23 17:33:28.997 Copy&Strong[7225:303] kkk
2016-03-23 17:33:29.006 Copy&Strong[7225:303] kkk is Lazy