iOS development-stringByReplacingOccurrencesOfString does not work

iOS development-stringByReplacingOccurrencesOfString does not work

String splicing and replacement are still frequently used in development. Some things are not noticed but it is easy to enter a misunderstanding. StringByReplacingOccurrencesOfString does not work. One:

NSMutableString *halfUrlStr = [NSMutableString stringWithFormat:@"%@",[LCReqURLManager requestWithURL:LC_MYINVEST_AUTH_BUYHISTORY]];

[halfUrlStr stringByReplacingOccurrencesOfString:@"{packageId}" withString:proID];

NSString *requestStr = [NSString stringWithFormat:@"%@%@",kUrlPreDomain,halfUrlStr];
 

In this way, I finally found that there was no replacement, and I also used NSMutableString to avoid suspicion. This is very embarrassing. What is the problem?

//
NSString *halfUrlStr = [NSString stringWithFormat:@"%@",[LCReqURLManager requestWithURL:LC_MYINVEST_AUTH_BUYHISTORY]];

halfUrlStr = [halfUrlStr stringByReplacingOccurrencesOfString:@"{packageId}" withString:proID];

NSString *requestStr = [NSString stringWithFormat:@"%@%@",kUrlPreDomain,halfUrlStr];
 

Just do an assignment operation, it is not possible to operate on the string directly.
Very strange, Apple's interpretation of this sentence is this:

/* Replace characters in range with the specified string, returning new string.
 

Returning a new string does not seem to have any effect. There are also methods that can be directly manipulated, such as stringByAppendingString, so it is very strange. When using stringByReplacingOccurrencesOfString, you still need to do an assignment operation and skip this pit.