Created
February 9, 2013 20:46
-
-
Save yetanotherchris/4747045 to your computer and use it in GitHub Desktop.
C# to Objective C by example #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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