Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios copy和mutableCopy在实际项目中有哪些应用?_Ios_Objective C - Fatal编程技术网

Ios copy和mutableCopy在实际项目中有哪些应用?

Ios copy和mutableCopy在实际项目中有哪些应用?,ios,objective-c,Ios,Objective C,copy和mutableCopy在实际项目中有哪些应用 NSString *str1 = @"test"; [str1 copy]; NSMutableString *mStr1 = [NSMutableString stringWithString:@"test002"]; [mStr1 mutableCopy]; NSArray *arry1 = [[NSArray alloc] initWithObjects:@"value1", @"value2",nil]; [arry1 copy

copy和mutableCopy在实际项目中有哪些应用

NSString *str1 = @"test";
[str1 copy];

NSMutableString *mStr1 = [NSMutableString stringWithString:@"test002"];
[mStr1 mutableCopy];

NSArray *arry1 = [[NSArray alloc] initWithObjects:@"value1", @"value2",nil];
[arry1 copy];

NSMutableArray *marry1 = [[NSMutableArray alloc] initWithObjects:@"value1", 
@"value2",nil];
[marry1 mutableCopy];

如果您面对的用例像您想要修改
NSArray
值,您可以将其可变副本分配给
NSMutableArray
并对其进行修改。

我知道它们的不同之处,但我想知道如何在实际项目中使用它们。在实际项目中使用它们是什么意思。该链接提供了它们的所有效果以及如何使用它们。是的!所以mutableCopy可以用来交换不可变到可变的对象。你们如何交换到不可变的对象?
NSArray *arry1 = [[NSArray alloc] initWithObjects:@"value1", @"value2",nil];
NSArray * testCopyArray =  [arry1 copy];  // returns immutable copy of array
NSMutableArray * testMutableCopyArray = [arry1 mutableCopy]; //// returns mutable copy of array
[testMutableCopyArray addObject:@"value3"]; // you can modify its values