- Joined
- Oct 7, 2009
- Messages
- 14
- Reaction score
- 0
- Points
- 1
- Location
- Singapore
What is the "correct"way of declaring NSString ?
I also realize this works:
"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
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]);
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