Which is the best way to initialize NSMutableString: allocinit, new, string?

Asked 2 years ago, Updated 2 years ago, 47 views

I have a question about initializing NSMutableString for objective-c.

NSMutableString*ms1 = NSMutableString string;
NSMutableString* ms2 = [[NSMutableString alloc] init];
NSMutableString* ms3 = [NSMutableString new];

Yes.

So I have a question.
·What is the ideal initialization method for objective-c?
·Also, why is the initialization method good?

That's all, thank you.

ios objective-c

2022-09-30 14:57

1 Answers

Any environment where ARC is enabled is the same.There is no change or difference.

The method new is a shortened form of alloc + init, so-called "Syntax Sugar".
There was a difference between alloc + init and string where alloc + init + autorelease is an abbreviated format.


2022-09-30 14:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.