View Single Post
Bracer

 
Bracer's Avatar
 
Member Since: Oct 07, 2009
Location: Singapore
Posts: 14
Bracer is on a distinguished road

Bracer is offline
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 );
}
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]);
"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 Thanks