12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- //
- // NSArray+RQExtension.m
- // XinShouJiaDao
- //
- // Created by 张嵘 on 2021/7/7.
- // Copyright © 2021 JCZ. All rights reserved.
- //
- #import "NSArray+RQExtension.h"
- @implementation NSArray (RQExtension)
- - (id)objAtPath:(NSIndexPath*)path {
- if (path.section < self.count ) {
- NSArray* subObj = self[path.section];
- if([subObj isKindOfClass:[NSArray class]] ||
- [subObj isKindOfClass:[NSMutableArray class]])
- {
- if (path.row < subObj.count) {
- return [self[path.section] objectAtIndex:path.row];
- }
- }
- }
-
- return nil;
- }
- /*
- * @brief 将数组随机打乱
- */
- - (NSArray *)rq_randomArray {
- // 转为可变数组
- NSMutableArray * tmp = self.mutableCopy;
- // 获取数组长度
- NSInteger count = tmp.count;
- // 开始循环
- while (count > 0) {
- // 获取随机角标
- NSInteger index = arc4random_uniform((int)(count - 1));
- // 获取角标对应的值
- id value = tmp[index];
- // 交换数组元素位置
- tmp[index] = tmp[count - 1];
- tmp[count - 1] = value;
- count --;
- }
- // 返回打乱顺序之后的数组
- return tmp.copy;
- }
- @end
|