将 NSArray 添加到 NSMutableArray [英] add a NSArray to NSMutableArray

查看:64
本文介绍了将 NSArray 添加到 NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个 NSArray 添加到我的 NSMutable(appdelegate 中的 init)

i want to add a NSArray to my NSMutable ( init in the appdelegate )

这是我的代码,每次按下按钮(男性、女性、情侣)时都会调用该方法,因此必须将 NSArray 添加到 MutableArray 但我不知道我尝试过但不起作用.:

this is my code, the method is call each time a button (male, female, couple) is pressed so an NSArray has to be add to the MutableArray but i don't know i tried stuff but doesnt work. :

     - (void) sexChoosen:(NSString *) sexe
{
    NSError *err;
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Boxes" inManagedObjectContext:context];
    [request setEntity:entity];

    NSArray *arrayForPredicate = [context executeFetchRequest:request error:&err];
    NSPredicate *sex;

    sex = [NSPredicate predicateWithFormat:@"sexe = %@", sexe];

    NSArray  *BoxWithSex = [arrayForPredicate filteredArrayUsingPredicate:sex];
    //NSMutableArray* tmp = [self createMutableArray:BoxWithSex];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    NSLog(@"FIRST  %@", appDelegate.myArray);

// HERE IS THE CODE TO ADD THE ARRAY TO MY NSMUTABLE ARRAY = AppDelegate *appDelegate

    NSLog(@"SECOND %@", appDelegate.myArray);

}

推荐答案

来自 NSMutableArray 文档:

From the NSMutableArray documentation:

"addObjectsFromArray:添加包含在另一个给定数组中的对象到接收数组内容的末尾."

"addObjectsFromArray: Adds the objects contained in another given array to the end of the receiving array’s content."

这篇关于将 NSArray 添加到 NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆