Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Why do you need to "alloc" for initWithCString and but doesn't for stringWithFormat ?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Bracer" data-source="post: 922723" data-attributes="member: 125415"><p>Why is it that these two are correct:</p><p>[code]</p><p>NSMutableString* CombinedText = [NSMutableString stringWithFormat:@"%d %d %d",1,2,3];</p><p>[/code]</p><p></p><p>and</p><p>[code]</p><p>NSMutableString* CombinedText = [[NSMutableString alloc] initWithCString:"String Data" ];</p><p>[/code]</p><p></p><p>The question is, why is it that you have to "alloc" when you are using the "initWithCString" function yet doesn't have to when you do stringWithFormat, I am puzzled because they BOTH returns a NSMutableString, so shouldn't they have similar initialization protocols ?</p><p>Yet when I try to:</p><p>[code]</p><p>NSMutableString* CombinedText = [ [NSMutableString alloc] stringWithFormat:@"%d %d %d",1,2,3];</p><p>[/code]</p><p>It crashes ?</p><p>Likewise if I were to remove "alloc" from initWithCString.</p></blockquote><p></p>
[QUOTE="Bracer, post: 922723, member: 125415"] Why is it that these two are correct: [code] NSMutableString* CombinedText = [NSMutableString stringWithFormat:@"%d %d %d",1,2,3]; [/code] and [code] NSMutableString* CombinedText = [[NSMutableString alloc] initWithCString:"String Data" ]; [/code] The question is, why is it that you have to "alloc" when you are using the "initWithCString" function yet doesn't have to when you do stringWithFormat, I am puzzled because they BOTH returns a NSMutableString, so shouldn't they have similar initialization protocols ? Yet when I try to: [code] NSMutableString* CombinedText = [ [NSMutableString alloc] stringWithFormat:@"%d %d %d",1,2,3]; [/code] It crashes ? Likewise if I were to remove "alloc" from initWithCString. [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Why do you need to "alloc" for initWithCString and but doesn't for stringWithFormat ?
Top