summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--objective-c.html.markdown25
1 files changed, 17 insertions, 8 deletions
diff --git a/objective-c.html.markdown b/objective-c.html.markdown
index 0131a34c..95012152 100644
--- a/objective-c.html.markdown
+++ b/objective-c.html.markdown
@@ -50,9 +50,8 @@ int main (int argc, const char * argv[])
// String
NSString *worldString = @"World";
- NSLog(@"Hello %@!", worldString); // prints => "Hello World!"
- // The mutable version of NSString is NSMutableString that allows to edit
- // individual characters or append strings together.
+ NSLog(@"Hello %@!", worldString); // prints => "Hello World!"
+ // NSMutableString is a mutable version of the NSString object.
NSMutableString *mutableString = [NSMutableString stringWithString:@"Hello"];
[mutableString appendString:@" World!"];
NSLog(@"%@", mutableString); // prints => "Hello World!"
@@ -98,11 +97,11 @@ int main (int argc, const char * argv[])
NSLog(@"%f", piDouble);
NSLog(@"%4.2f", piDouble); // prints => "3.14"
- // NSDecimalNumber is Objective-C's fixed-point class more precise then float or double
+ // NSDecimalNumber is a fixed-point class that's more precise then float or double
NSDecimalNumber *oneDecNum = [NSDecimalNumber decimalNumberWithString:@"10.99"];
NSDecimalNumber *twoDecNum = [NSDecimalNumber decimalNumberWithString:@"5.002"];
- // NSDecimal isn't able to use standard +, -, *, / operators. NSDecimalNumber has its own:
- [oneDecNum decimalNumberByAdding:twoDecNum]; // add
+ // NSDecimalNumber isn't able to use standard +, -, *, / operators so it provides its own:
+ [oneDecNum decimalNumberByAdding:twoDecNum];
[oneDecNum decimalNumberBySubtracting:twoDecNum];
[oneDecNum decimalNumberByMultiplyingBy:twoDecNum];
[oneDecNum decimalNumberByDividingBy:twoDecNum];
@@ -132,10 +131,12 @@ int main (int argc, const char * argv[])
NSDictionary *aDictionary = @{ @"key1" : @"value1", @"key2" : @"value2" };
NSObject *valueObject = aDictionary[@"A Key"];
NSLog(@"Object = %@", valueObject); // Print "Object = (null)"
+ // NSMutableDictionary also available as mutable dictionary object.
// Set object
NSSet *set = [NSSet setWithObjects:@"Hello", @"Hello", @"World", nil];
- NSLog(@"%@", set); // prints => {(Hello, World)}
+ NSLog(@"%@", set); // prints => {(Hello, World)} (may be in different order)
+ // NSMutableSet also available as mutable set object.
///////////////////////////////////////
// Operators
@@ -216,6 +217,14 @@ int main (int argc, const char * argv[])
// "2,"
// "3,"
+ // Object for loop statement. Can be used with any Objective-C object type.
+ for (id item in values) {
+ NSLog(@"%@,", item);
+ } // => prints "0,"
+ // "1,"
+ // "2,"
+ // "3,"
+
// Try-Catch-Finally statements
@try
{
@@ -278,7 +287,7 @@ _count = 5;
NSLog(@"%d", _count); // prints => 5
// To access public variable outside implementation file, @property generates setter method
// automatically. Method name is 'set' followed by @property variable name:
-[objInitVar setCount:10]; // objInitVar = variable of object instance @property resides in.
+[objInitVar setCount:10]; // objInitVar = random object instance @property resides in.
NSLog(@"%@", [objInitVar count]); // prints => 10
// Methods