summaryrefslogtreecommitdiffhomepage
path: root/objective-c.html.markdown
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2013-12-23 02:26:11 -0600
committerLevi Bostian <levi.bostian@gmail.com>2013-12-30 18:14:04 -0600
commit18f669089e0f5a65adfdfeddaa571a801dd4b865 (patch)
tree59a8efa691aec0b00c263241491bac5f9db0d0cd /objective-c.html.markdown
parent0b73244aa3c53d51a7031a04a6cb7f85895af101 (diff)
Add examples of methods to work with NSSets.
Add note of NSSets being unordered. Remove for loop to iterate on NSSet. Moved for loop to loop section.
Diffstat (limited to 'objective-c.html.markdown')
-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