summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--objective-c.html.markdown29
1 files changed, 25 insertions, 4 deletions
diff --git a/objective-c.html.markdown b/objective-c.html.markdown
index fc4b2900..c3df514b 100644
--- a/objective-c.html.markdown
+++ b/objective-c.html.markdown
@@ -25,15 +25,28 @@ Multi-line comments look like this.
// main with an integer return type.
int main (int argc, const char * argv[])
{
- // Create an autorelease pool to manage the memory into your program
+ // Create an autorelease pool to manage the memory into the program
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Use NSLog to print lines to the console
NSLog(@"Hello World!"); // Print the string "Hello World!"
- // String object
- NSString *worldString = @"World";
+ ///////////////////////////////////////
+ // Types & Variables
+ ///////////////////////////////////////
+
+ // Primitive declarations
+ int myPrimitive;
+
+ // Object declarations
+ // Put the * in front of the variable names for strongly-typed object declarations
+ MyClass *myObject1; // Strong typing
+ id myObject2; // Weak typing
// %@ is an object
+ NSLog(@"%@ and %@", myObject1, myObject2); // Print "(null) and (null)"
+
+ // String
+ NSString *worldString = @"World";
NSLog(@"Hello %@!", worldString); // Print "Hello World!"
// Character literals
@@ -50,6 +63,10 @@ int main (int argc, const char * argv[])
unsigned int fortyTwoUnsigned = [fortyTwoUnsignedNumber unsignedIntValue];
NSLog(@"%u", fortyTwoUnsigned);
+ NSNumber *fortyTwoShortNumber = [NSNumber numberWithShort:42];
+ short fortyTwoShort = [fortyTwoShortNumber shortValue];
+ NSLog(@"%hi", fortyTwoShort);
+
NSNumber *fortyTwoLongNumber = @42L;
long fortyTwoLong = [fortyTwoLongNumber longValue];
NSLog(@"%li", fortyTwoLong);
@@ -77,10 +94,14 @@ int main (int argc, const char * argv[])
NSObject *valueObject = aDictionary[@"A Key"];
NSLog(@"Object = %@", valueObject); // Print "Object = (null)"
+ ///////////////////////////////////////
+ // Operators
+ ///////////////////////////////////////
+
// Clean up the memory you used into your program
[pool drain];
- // End your program
+ // End the program
return 0;
}