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.
This commit is contained in:
Levi Bostian 2013-12-23 02:26:11 -06:00
parent 0b73244aa3
commit 18f669089e

View File

@ -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