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
Which of these two ways are the best NSString Initializer ?
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: 921132" data-attributes="member: 125415"><p>What is the "correct"way of declaring NSString ?</p><p></p><p>[code]</p><p>-(void) PrintMessage</p><p>{</p><p> NSString* Variable1 = [[NSString alloc] initWithCString: "This is Variable 1 String." ];</p><p> NSString* Variable2 = @"This is Variable 2 String.";</p><p> </p><p> NSLog(@"\n\n%@\n%@",Variable1,Variable2 );</p><p>}</p><p>[/code]</p><p></p><p>I also realize this works:</p><p>[code]</p><p>id Variable1 = [[NSString alloc] initWithCString: "This is Variable 1 String." ];</p><p>id Variable2 = @"This is Variable 2 String.";</p><p> </p><p>NSLog(@"\n\n%@\n%@\n\n",Variable1,Variable2 );</p><p>printf("\nThis is \"printf\" in action: \n%s\n%s\n",[Variable1 cString],[Variable2 cString]);</p><p>[/code]</p><p>"id" is so amazing ! It's like the "Object" or "[]" in Actionscript 3 or the Variant type in Visual Basic !</p><p>I am very surprise that Variable2 just "knows" that it's a NSString, I figure it's smart enough to know that when the value assigns to it is of NSString type and it convert itself automatically, absolute brilliant from my point of view ;p</p></blockquote><p></p>
[QUOTE="Bracer, post: 921132, member: 125415"] What is the "correct"way of declaring NSString ? [code] -(void) PrintMessage { NSString* Variable1 = [[NSString alloc] initWithCString: "This is Variable 1 String." ]; NSString* Variable2 = @"This is Variable 2 String."; NSLog(@"\n\n%@\n%@",Variable1,Variable2 ); } [/code] I also realize this works: [code] id Variable1 = [[NSString alloc] initWithCString: "This is Variable 1 String." ]; id Variable2 = @"This is Variable 2 String."; NSLog(@"\n\n%@\n%@\n\n",Variable1,Variable2 ); printf("\nThis is \"printf\" in action: \n%s\n%s\n",[Variable1 cString],[Variable2 cString]); [/code] "id" is so amazing ! It's like the "Object" or "[]" in Actionscript 3 or the Variant type in Visual Basic ! I am very surprise that Variable2 just "knows" that it's a NSString, I figure it's smart enough to know that when the value assigns to it is of NSString type and it convert itself automatically, absolute brilliant from my point of view ;p [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Which of these two ways are the best NSString Initializer ?
Top