// // main.m // OC3_Copy及MultableCopy // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> //copy mutableCopy int main(int argc, const char * argv[]) { @autoreleasepool { //copy 把可变对象及不可变对象 copy生成不可变对象 NSString *str = @"hello world"; NSString *str1 = [str copy]; //[str1 insertString:@"qianfeng" atIndex:4]; NSLog(@"str = %p str1 = %p", str, str1); NSLog(@"str1 = %@", str1); NSMutableString *str2 = [NSMutableString stringWithString:@"hello world"]; NSString *str3 = [str2 copy]; //[str3 insertString:@"qianfeng" atIndex:4]; NSLog(@"str3 = %@", str3); //mutableCopy 把可变或者不可变对象copy生成可变对象 NSString *str4 = @"qianfeng"; NSMutableString *str5 = [str4 mutableCopy]; [str5 insertString:@"hello" atIndex:4]; NSLog(@"str5 = %@", str5); NSMutableString *str6 = [NSMutableString stringWithString:@"qianfeng"]; NSMutableString *str7 = [str6 mutableCopy]; [str7 insertString:@"world" atIndex:4]; NSLog(@"str7 = %@", str7); } return 0; }
时间: 2024-10-13 16:15:40