Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.