Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Created February 9, 2013 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetanotherchris/4747045 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4747045 to your computer and use it in GitHub Desktop.
C# to Objective C by example #5
-(NSString*) stringExample
{
// You prepend a string with @ to indicate to the objective-c compiler that it's an NSString.
// Release messages (see above) aren't required for these and are ignored.
NSString *result = @"initial";
// Strings are immutable as in .NET, however not interned so the same
// string can exist in two memory locations. There is a subclass of
// NSString called NSMutableString which is akin to a StringBuilder.
result = [result stringByAppendingString:@" test"];
return result;
}
-(NSString*) stringFormatExample : (NSString*) title : (NSString*) firstName
{
// This is the equivalent in C# of 'return firstname + " " + firstName;' or the String.format equivalent
// As far as I know, there is no way of concatenation without using formatting.
// %@ is the string format to print an object, like {0}. The overriden description
// method controls the output for an object, which is demonstrated below.
NSString *result = [NSString stringWithFormat: @"%@ %@",title,firstName];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment