/* NSArray.h
Copyright (c) 1994-2013, Apple Inc. All rights reserved.
*/
#import <Foundation/NSObject.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSRange.h>
#import <Foundation/NSObjCRuntime.h>
@class NSData, NSIndexSet, NSString, NSURL;
/**************** Immutable Array ****************/
#pragma mark - NSArray
@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSSecureCoding, NSFastEnumeration>
- (NSUInteger)count; // 元素個數(shù)
- (id)objectAtIndex:(NSUInteger)index; // 元素索引
@end
@interface NSArray (NSExtendedArray)
- (NSArray *)arrayByAddingObject:(id)anObject; // 增加一個元素流译,返回一個新的數(shù)組
- (NSArray *)arrayByAddingObjectsFromArray:(NSArray *)otherArray; // 從另一個數(shù)組中拷貝全部元素到新的數(shù)組
- (NSString *)componentsJoinedByString:(NSString *)separator; // 將數(shù)組元素用分隔符來拼接成一個字符串
- (BOOL)containsObject:(id)anObject; // 判斷是否包含某一個元素
- (NSString *)description; // 重寫父類的 description 方法
- (NSString *)descriptionWithLocale:(id)locale; //
- (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level;
- (id)firstObjectCommonWithArray:(NSArray *)otherArray;
- (void)getObjects:(id __unsafe_unretained [])objects range:(NSRange)range; // 取得range范圍類的所有元素
- (NSUInteger)indexOfObject:(id)anObject; // 返回某一個元素的索引
- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range; // 返回在range范圍內(nèi)的某一元素的索引
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject; // 返回和某一對象相同的元素的索引
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(NSRange)range; // 返回在range范圍內(nèi)和某一對象相同的元素的索引
- (BOOL)isEqualToArray:(NSArray *)otherArray; // 判斷兩個數(shù)組是否相等
- (id)firstObject NS_AVAILABLE(10_6, 4_0); // 返回首元素
- (id)lastObject; // 返回最后一個元素
- (NSEnumerator *)objectEnumerator; // 返回一個數(shù)組迭代器
- (NSEnumerator *)reverseObjectEnumerator; // 返回一個反序迭代器
- (NSData *)sortedArrayHint;
- (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context;
- (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context hint:(NSData *)hint;
- (NSArray *)sortedArrayUsingSelector:(SEL)comparator;
- (NSArray *)subarrayWithRange:(NSRange)range;
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile; // 將數(shù)組寫入到文件宴偿,并選擇是否采用原子性
- (BOOL)writeToURL:(NSURL *)url atomically:(BOOL)atomically; // 將數(shù)組寫到URL中
- (void)makeObjectsPerformSelector:(SEL)aSelector; // 讓某一個元素響應(yīng)某個方法
- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument;
- (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes;
- (id)objectAtIndexedSubscript:(NSUInteger)idx NS_AVAILABLE(10_8, 6_0);
#pragma mark - if NS_BLOCKS_AVAILABLE
#if NS_BLOCKS_AVAILABLE
// 遍歷數(shù)組元素
- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block NS_AVAILABLE(10_6, 4_0);
- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block NS_AVAILABLE(10_6, 4_0);
- (void)enumerateObjectsAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block NS_AVAILABLE(10_6, 4_0);
- (NSUInteger)indexOfObjectPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
- (NSUInteger)indexOfObjectWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
- (NSUInteger)indexOfObjectAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
- (NSIndexSet *)indexesOfObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
- (NSIndexSet *)indexesOfObjectsWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
- (NSIndexSet *)indexesOfObjectsAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0);
//
- (NSArray *)sortedArrayUsingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0);
- (NSArray *)sortedArrayWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0);
typedef NS_OPTIONS(NSUInteger, NSBinarySearchingOptions) {
NSBinarySearchingFirstEqual = (1UL << 8),
NSBinarySearchingLastEqual = (1UL << 9),
NSBinarySearchingInsertionIndex = (1UL << 10),
};
- (NSUInteger)indexOfObject:(id)obj inSortedRange:(NSRange)r options:(NSBinarySearchingOptions)opts usingComparator:(NSComparator)cmp NS_AVAILABLE(10_6, 4_0); // binary search
#endif
@end
#pragma mark - NSArray的初始化
@interface NSArray (NSArrayCreation)
+ (instancetype)array; // 創(chuàng)建一個數(shù)組
+ (instancetype)arrayWithObject:(id)anObject; // 創(chuàng)建一個帶有某對象的數(shù)組
+ (instancetype)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt; // 創(chuàng)建一個帶有多個對象的數(shù)組
+ (instancetype)arrayWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION; // 創(chuàng)建一個帶有多個對象的數(shù)組
+ (instancetype)arrayWithArray:(NSArray *)array; // 從數(shù)組創(chuàng)建數(shù)組
- (instancetype)init; // 初始化
- (instancetype)initWithObjects:(const id [])objects count:(NSUInteger)cnt; // 帶有多個對象的數(shù)組的初始化
- (instancetype)initWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION; // 帶有多個對象的數(shù)組的初始化
- (instancetype)initWithArray:(NSArray *)array; // 初始化并從數(shù)組創(chuàng)建數(shù)組
- (instancetype)initWithArray:(NSArray *)array copyItems:(BOOL)flag;
+ (id /* NSArray * */)arrayWithContentsOfFile:(NSString *)path; // 從文件創(chuàng)建數(shù)組
+ (id /* NSArray * */)arrayWithContentsOfURL:(NSURL *)url; // 從URL創(chuàng)建數(shù)組
- (id /* NSArray * */)initWithContentsOfFile:(NSString *)path; // 從文件創(chuàng)建數(shù)組
- (id /* NSArray * */)initWithContentsOfURL:(NSURL *)url; // 從URL創(chuàng)建數(shù)組
@end
@interface NSArray (NSDeprecated)
/* This method is unsafe because it could potentially cause buffer overruns. You should use -getObjects:range: instead.
*/
- (void)getObjects:(id __unsafe_unretained [])objects;
@end
/**************** Mutable Array ****************/
#pragma mark - NSMutableArray
@interface NSMutableArray : NSArray
- (void)addObject:(id)anObject; // 增加數(shù)組元素
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index; // 某個索引處插入元素
- (void)removeLastObject; // 刪除最后一個元素
- (void)removeObjectAtIndex:(NSUInteger)index; // 刪除某一個索引處的元素
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject; // 替換某個索引處的元素
@end
@interface NSMutableArray (NSExtendedMutableArray)
- (void)addObjectsFromArray:(NSArray *)otherArray; // 將某一數(shù)組中的元素加入到數(shù)組中
- (void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2; // 交換兩個索引處的元素
- (void)removeAllObjects; // 刪除所有的元素
- (void)removeObject:(id)anObject inRange:(NSRange)range; // 刪除某個范圍內(nèi)的某一元素
- (void)removeObject:(id)anObject; // 刪除某一元素
- (void)removeObjectIdenticalTo:(id)anObject inRange:(NSRange)range; // 刪除某個范圍內(nèi)和某對象相同的元素
- (void)removeObjectIdenticalTo:(id)anObject; // 刪除和某個對象相同的元素
- (void)removeObjectsFromIndices:(NSUInteger *)indices numIndices:(NSUInteger)cnt NS_DEPRECATED(10_0, 10_6, 2_0, 4_0);
- (void)removeObjectsInArray:(NSArray *)otherArray;
- (void)removeObjectsInRange:(NSRange)range; // 刪除某個范圍內(nèi)的所有的元素
- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray range:(NSRange)otherRange; // 替換
- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray;
- (void)setArray:(NSArray *)otherArray;
- (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context;
- (void)sortUsingSelector:(SEL)comparator;
- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes; // 某些索引處插入某些對象
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects; // 替換某些索引處的元素
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx NS_AVAILABLE(10_8, 6_0);
#if NS_BLOCKS_AVAILABLE
- (void)sortUsingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0);
- (void)sortWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0);
#endif
@end
@interface NSMutableArray (NSMutableArrayCreation)
+ (instancetype)arrayWithCapacity:(NSUInteger)numItems;
- (instancetype)init; /* designated initializer */
- (instancetype)initWithCapacity:(NSUInteger)numItems; /* designated initializer */
@end
NSArray.h
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門锡凝,熙熙樓的掌柜王于貴愁眉苦臉地迎上來粘昨,“玉大人垢啼,你說我怎么就攤上這事窜锯≌派觯” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵锚扎,是天一觀的道長吞瞪。 經(jīng)常有香客問我,道長驾孔,這世上最難降的妖魔是什么芍秆? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮翠勉,結(jié)果婚禮上妖啥,老公的妹妹穿的比我還像新娘。我一直安慰自己对碌,他們只是感情好荆虱,可當我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著朽们,像睡著了一般怀读。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上骑脱,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼条舔!你這毒婦竟也來了枫耳?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布姜贡,位于F島的核電站试吁,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏楼咳。R本人自食惡果不足惜熄捍,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望母怜。 院中可真熱鬧余耽,春花似錦、人聲如沸苹熏。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽柜裸。三九已至缕陕,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間疙挺,已是汗流浹背扛邑。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- mac上安裝python sftp 的時候出現(xiàn) openssl/opensslv.h' file not foun...