NSMutableArray *username = [NSMutableArray arrayWithObjects: @"Peter",@"Mary", @"John", @"David" ,@"Susan", nil]; |
2. Common class method [ + ] and instance methods [ - ]:
+ | array |
+ | arrayWithObjects |
- | (NSUInteger) count |
- | objectAtIndex: (NSSInteger) index |
- | (void) addObject: (id) anObject |
- | (void) insertObject: (id) anObject atIndex: (NSUInteger) index |
- | (void) removeLastObject |
- | (void) removeObjectAtIndex: (NSUInteger) index |
- | (void) removeAllObjects |
- | |
- |
-: Instance Method: 需先實體化才可以使用的方法,假設str1 已經是NSString 文字實體 (生完仔, 對仔落指令)
[+] arrayWithObjects: (NSString *) format
[-] (NSUInteger) count
[-] (NSUInteger) objectAtIndex: (NSSInteger) index
[-] (void) addObject: (id) anObject
[-] (void) insertObject: (id) anObject atIndex: (NSUInteger) index
[-] (void) removeLastObject
[-] (void) removeObjectAtIndex: (NSUInteger) index
[-] (void) removeAllObjects
Reference: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableArray/removeAllObjects
NSMutableArray
1a. Verify that the Foundation array classes are bounds checked:
- Create an NSMutableArray and populate it with three NSString objects.
- Using the method objectAtIndex:, try to retrieve an object from index -1.
- Using the method insertObject:atIndex:, try to insert another NSString at index -1. What happens?
- Now try to insert the new string at index 3. Explain your results.
Sort an NSArray
1. Create an NSArray that holds the following strings: @"Raspberry", @"Peach", @"Banana", @"Blackberry", @"Blueberry", and @"Apple".
2. Obtain a sorted version of the array using the NSArray method sortedArrayUsingSelector:. Use the selector for the NSString method caseInsensitiveCompare: as the argument. You should read the documentation for sortedArrayUsingSelector: and caseInsensitiveCompare:
before proceeding.
3.Log the contents of the newly created sorted array.