NSArray(FWSafeType)
@interface NSArray<__covariant ObjectType> (FWSafeType)
/**
安全获取对象
@param index 索引
@return 对象
*/
- (nullable ObjectType)fw_objectAtIndex:(NSInteger)index NS_REFINED_FOR_SWIFT;
/**
安全获取子数组
@param range 范围
@return 对象数组
*/
- (nullable NSArray<ObjectType> *)fw_subarrayWithRange:(NSRange)range NS_REFINED_FOR_SWIFT;
@end
Undocumented
-
安全获取对象
Declaration
Objective-C
- (nullable ObjectType)fw_objectAtIndex:(NSInteger)index;
Parameters
index
索引
Return Value
对象
-
安全获取子数组
Declaration
Objective-C
- (nullable NSArray<ObjectType> *)fw_subarrayWithRange:(NSRange)range;
Parameters
range
范围
Return Value
对象数组
-
过滤数组元素,返回YES的obj重新组装成一个数组
Declaration
Objective-C
- (nonnull NSArray<ObjectType> *)fw_filterWithBlock: (nonnull BOOL (^)(ObjectType _Nonnull __strong))block;
-
映射数组元素,返回的obj重新组装成一个数组
Declaration
Objective-C
- (nonnull NSArray *)fw_mapWithBlock: (nonnull id _Nullable (^)(ObjectType _Nonnull __strong))block;
-
匹配数组第一个元素,返回满足条件的第一个obj
Declaration
Objective-C
- (nullable ObjectType)fw_matchWithBlock: (nonnull BOOL (^)(ObjectType _Nonnull __strong))block;
-
从数组中随机取出对象,如@[@“a”, @“b”, @“c”]随机取出@“b”
Declaration
Objective-C
@property (nonatomic, readonly, nullable) ObjectType fw_randomObject;
-
从数组中按照权重随机取出对象,如@[@“a”, @“b”, @“c”]按照@[@0, @8, @02]大概率取出@“b",不会取出@"a”
Declaration
Objective-C
- (nullable ObjectType)fw_randomObject:(nonnull NSArray *)weights;