OC中获取任意结构数组的所有元素内容方法

2018-08-14  本文已影响0人  A橙汁不加橙

#import"ViewController.h"@interfaceViewController()@property(nonatomic,strong) NSMutableArray * mutableArry;@end@implementationViewController- (void)viewDidLoad {

    [super viewDidLoad];

    _mutableArry = [[NSMutableArray alloc]init];

    NSArray * ary = @[@[@[@[@[@[@"woqu"],@"888"]]]],@[@"123"],@[@[@[@"000",@"010"]]],@"321",@[@"555",@[@"666"]],@"777"];

[self getAllObject:ary and:0];

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"等于:%@",_mutableArry);

}

-(void)getAllObject:(NSArray *)array and:(int)num{

    while (num

    if (![array[num] isKindOfClass:[NSArray class]]) {

        [_mutableArry addObject:array[num]];

        num++;

        continue;

    }else if([array[num] isKindOfClass:[NSArray class]]){

        [self getAllObject:array[num] and:0];

        num++;

    }

    }

}

上一篇下一篇

猜你喜欢

热点阅读