oc copy

来源:互联网 发布:完美假期周晨曦淘宝店 编辑:程序博客网 时间:2024/06/06 02:41
//// main.m// Copy//// Created by liyang on 15-6-12.// Copyright (c) 2015年 liyang. All rights reserved.//#import #import "Goodstudent.h"#import "student.h"#pragma mark 字符copy#pragma mark 字符copy (深拷贝)void stringcopy(){ NSString *str = [[NSString alloc]initWithFormat:@"age is %i",10]; NSMutableString *strMut = [str mutableCopy]; NSLog( @"%zi",[str retainCount]); NSLog(@"%zi",[strMut retainCount]); [strMut appendString:@"1234"]; NSLog(@"%@",str); NSLog(@"%@",strMut); NSLog( @"%i ",str == strMut); NSLog(@"%p",str); NSLog(@"%p",strMut); [strMut release]; [str release];}#pragma mark 字符copy (浅拷贝)void stringmutablecopy(){ NSString *str = [[NSString alloc]initWithFormat:@"age is %i",10]; NSLog( @"%zi",[str retainCount]); NSString *strMut = [str copy]; NSLog( @"%i ",str == strMut); NSLog(@"%zi",[strMut retainCount]); [strMut release]; [str release];}#pragma mark 字符copy (深拷贝)void mutablestringcopy(){ NSMutableString * strmuta =[ NSMutableString stringWithFormat:@"str is %i",20]; NSString *string = [ strmuta copy]; NSLog(@"%p",strmuta); NSLog(@"%p",string); [string release];}#pragma mark 字符copy (深拷贝)void mutablesTomustringcopy(){ NSMutableString * strmuta =[ NSMutableString stringWithFormat:@"str is %i",20]; NSMutableString *string = [ strmuta mutableCopy]; NSLog(@"%p",strmuta); NSLog(@"%p",string); [string release];}void studentcopy(){ student *stu = [[[student alloc]init ]autorelease]; NSMutableString * strmuta =[ NSMutableString stringWithFormat:@"str is %i",20]; stu.name = strmuta; [strmuta appendString:@"asasasddddd"]; NSLog(@"%@", strmuta); NSLog(@"%@",stu.name); }void studentNamecopy(){ /* student *stu = [student studentwithName:@"stu1"]; student *stugood = [stu copy]; NSLog(@"%@",stu); NSLog(@"%@",stugood); [stugood release];*/ Goodstudent *good = [Goodstudent goodstudentWithage:10 name:@"stugood"]; Goodstudent *stu2 = good; NSLog(@"%@", good); NSLog(@"%@",stu2);}int main(int argc, const char * argv[]){ @autoreleasepool { // stringcopy(); studentNamecopy(); } return 0;}
0 0
原创粉丝点击