Skip to content

Commit

Permalink
给 NSArray 的一些 block 添加 NS_NOESCAPE
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtmelon committed May 2, 2020
1 parent e0c6fdf commit 0e930ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions QMUIKit/UIKitExtensions/NSArray+QMUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSArray<ObjectType> (QMUI)

/**
Expand All @@ -28,7 +30,7 @@
/**
* 将多维数组打平成一维数组再遍历所有子元素
*/
- (void)qmui_enumerateNestedArrayWithBlock:(void (^)(id obj, BOOL *stop))block;
- (void)qmui_enumerateNestedArrayWithBlock:(void (NS_NOESCAPE ^)(id obj, BOOL *stop))block;

/**
* 将多维数组递归转换成 mutable 多维数组
Expand All @@ -38,11 +40,13 @@
/**
* 过滤数组元素,将 block 返回 YES 的 item 重新组装成一个数组返回
*/
- (NSArray<ObjectType> *)qmui_filterWithBlock:(BOOL (^)(ObjectType item))block;
- (NSArray<ObjectType> *)qmui_filterWithBlock:(BOOL (NS_NOESCAPE ^)(ObjectType item))block;

/**
* 转换数组元素,将每个 item 都经过 block 转换成一遍 返回转换后的新数组
*/
- (NSArray *)qmui_mapWithBlock:(id (^)(ObjectType item))block;
- (NSArray *)qmui_mapWithBlock:(id (NS_NOESCAPE ^)(ObjectType item))block;

@end

NS_ASSUME_NONNULL_END
6 changes: 3 additions & 3 deletions QMUIKit/UIKitExtensions/NSArray+QMUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ + (instancetype)qmui_arrayWithObjects:(id)object, ... {
return result.copy;
}

- (void)qmui_enumerateNestedArrayWithBlock:(void (^)(id, BOOL *))block {
- (void)qmui_enumerateNestedArrayWithBlock:(void (NS_NOESCAPE ^)(id, BOOL *))block {
BOOL stop = NO;
for (NSInteger i = 0; i < self.count; i++) {
id object = self[i];
Expand All @@ -69,7 +69,7 @@ - (NSMutableArray *)qmui_mutableCopyNestedArray {
return mutableResult;
}

- (NSArray *)qmui_filterWithBlock:(BOOL (^)(id))block {
- (NSArray *)qmui_filterWithBlock:(BOOL (NS_NOESCAPE ^)(id))block {
if (!block) {
return self;
}
Expand All @@ -84,7 +84,7 @@ - (NSArray *)qmui_filterWithBlock:(BOOL (^)(id))block {
return [result copy];
}

- (NSArray *)qmui_mapWithBlock:(id (^)(id item))block {
- (NSArray *)qmui_mapWithBlock:(id (NS_NOESCAPE ^)(id item))block {
if (!block) {
return self;
}
Expand Down

0 comments on commit 0e930ab

Please sign in to comment.