Ojbect-C2 3、NSArray和NSMutableArray数组的使用

Adopted Protocols

NSCoding
  • encodeWithCoder:

  • initWithCoder:

NSCopying
  • copyWithZone:

NSMutableCopying
  • mutableCopyWithZone:

NSFastEnumeration
  • countByEnumeratingWithState:objects:count:

Tasks

Creating an Array

  • + array
  • + arrayWithArray:   --
  • + arrayWithContentsOfFile: --从文件中初始化数组
  • + arrayWithContentsOfURL:
  • + arrayWithObject:   --只能初始化一个元素
  • + arrayWithObjects: --初始化多个元素
  • + arrayWithObjects:count:

Initializing an Array

  • – init
  • – initWithArray:
  • – initWithArray:copyItems:
  • – initWithContentsOfFile:
  • – initWithContentsOfURL:
  • – initWithObjects:
  • – initWithObjects:count:

Querying an Array

  • – containsObject:   -- 是否包含字符串
  • – count --获取元素中的个数
  • – getObjects:range:
  • – firstObject
  • – lastObject
  • – objectAtIndex:   --访问数组中的某个元素
  • – objectAtIndexedSubscript:
  • – objectsAtIndexes:
  • – objectEnumerator
  • – reverseObjectEnumerator
  • – getObjects: Deprecated in OS X v10.6

Finding Objects in an Array

  • – indexOfObject:
  • – indexOfObject:inRange:
  • – indexOfObjectIdenticalTo:
  • – indexOfObjectIdenticalTo:inRange:
  • – indexOfObjectPassingTest:
  • – indexOfObjectWithOptions:passingTest:
  • – indexOfObjectAtIndexes:options:passingTest:
  • – indexesOfObjectsPassingTest:
  • – indexesOfObjectsWithOptions:passingTest:
  • – indexesOfObjectsAtIndexes:options:passingTest:
  • – indexOfObject:inSortedRange:options:usingComparator:

Sending Messages to Elements

  • – makeObjectsPerformSelector:
  • – makeObjectsPerformSelector:withObject:
  • – enumerateObjectsUsingBlock:
  • – enumerateObjectsWithOptions:usingBlock:
  • – enumerateObjectsAtIndexes:options:usingBlock:

Comparing Arrays

  • – firstObjectCommonWithArray:
  • – isEqualToArray:

Deriving New Arrays    

  • – arrayByAddingObject:   --追加数组的内容
  • – arrayByAddingObjectsFromArray:
  • – filteredArrayUsingPredicate:
  • – subarrayWithRange:

Sorting

  • – sortedArrayHint
  • – sortedArrayUsingFunction:context:
  • – sortedArrayUsingFunction:context:hint:
  • – sortedArrayUsingDescriptors:
  • – sortedArrayUsingSelector:
  • – sortedArrayUsingComparator:
  • – sortedArrayWithOptions:usingComparator:

Working with String Elements

  • – componentsJoinedByString:   --   数组-->字符串

Creating a Description

  • – description
  • – descriptionWithLocale:
  • – descriptionWithLocale:indent:
  • – writeToFile:atomically:
  • – writeToURL:atomically:

Collecting Paths

  • – pathsMatchingExtensions:

Key-Value Observing

  • – addObserver:forKeyPath:options:context:
  • – removeObserver:forKeyPath:
  • – removeObserver:forKeyPath:context:
  • – removeObserver:fromObjectsAtIndexes:forKeyPath:context:
  • – addObserver:toObjectsAtIndexes:forKeyPath:options:context:
  • – removeObserver:fromObjectsAtIndexes:forKeyPath:

Key-Value Coding

  • – setValue:forKey:
  • – valueForKey:






NSMutableArray

Tasks

Creating and Initializing a Mutable Array

  • + arrayWithCapacity:
  • – initWithCapacity:
  • – init

Adding Objects

  • – addObject:
  • – addObjectsFromArray:
  • – insertObject:atIndex:
  • – insertObjects:atIndexes:

Removing Objects

  • – removeAllObjects
  • – removeLastObject
  • – removeObject:
  • – removeObject:inRange:
  • – removeObjectAtIndex:
  • – removeObjectsAtIndexes:
  • – removeObjectIdenticalTo:
  • – removeObjectIdenticalTo:inRange:
  • – removeObjectsInArray:
  • – removeObjectsInRange:
  • – removeObjectsFromIndices:numIndices: Deprecated in OS X v10.6

Replacing Objects

  • – replaceObjectAtIndex:withObject:
  • – setObject:atIndexedSubscript:
  • – replaceObjectsAtIndexes:withObjects:
  • – replaceObjectsInRange:withObjectsFromArray:range:
  • – replaceObjectsInRange:withObjectsFromArray:
  • – setArray:

Filtering Content

  • – filterUsingPredicate:

Rearranging Content

  • – exchangeObjectAtIndex:withObjectAtIndex:
  • – sortUsingDescriptors:
  • – sortUsingComparator:
  • – sortWithOptions:usingComparator:
  • – sortUsingFunction:context:
  • – sortUsingSelector:

Class Methods


你可能感兴趣的:(Ojbect-C2 3、NSArray和NSMutableArray数组的使用)