diff options
author | Yannick Loriot <yannick.loriot@gmail.com> | 2013-08-13 16:04:20 +0200 |
---|---|---|
committer | Yannick Loriot <yannick.loriot@gmail.com> | 2013-08-13 16:04:20 +0200 |
commit | 0040ce616b4e27a182834cd2fd03aacc2561a198 (patch) | |
tree | 01258d4c89dd1cc4687f9fa3a41d84aa8983ffba | |
parent | 947c137680c2699bdb118b63460c560bac1fdd3c (diff) |
[UPDATE] Object Declaration
-rw-r--r-- | objective-c.html.markdown | 29 |
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; } |