将NSArray添加到NSMutableArray

时间:2012-05-14 14:51:06

标签: objective-c nsmutablearray nsarray

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

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

     - (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);

}

1 个答案:

答案 0 :(得分:7)

来自NSMutableArray documentation

  

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