码迷,mamicode.com
首页 > 其他好文 > 详细

OC3_Copy及MultableCopy

时间:2015-06-19 20:14:55      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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;
}

 

OC3_Copy及MultableCopy

标签:

原文地址:http://www.cnblogs.com/0515offer/p/4589556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!