Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8607277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:18:49+00:00 2026-06-12T03:18:49+00:00

I have NSArray1 = (1, 5, 2) and NSArray2 = (1, 3, 5) i

  • 0

I have NSArray1 = (1, 5, 2)
and NSArray2 = (1, 3, 5)

i want to array1 + array2 = (should return) = (2, 8, 7)

(in fact is it even possible to do this with NSArray)?

Heres a similar question
Adding two arrays together
(but this adds the values of the second array onto the end of the first array)

NSArray *a = [NSArray arrayWithObjects: @"1" ,@"2",@"3",nil];
NSArray *b = [NSArray arrayWithObjects: @"1" ,@"2",@"3",nil];
NSMutableArray *c = [[NSMutableArray alloc]init];
c = [a addObjectsFromArray:b];

// just a test code . . . .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:18:50+00:00Added an answer on June 12, 2026 at 3:18 am

    If it’s a C array, then just do

    int newArray[3];
    for (int i=0;i<3;i++)
        newArray[i] = array1[i]+array2[i];
    

    But if it’s a NSArray with NSNumbers (You can’t have primitives in NSArray), then just do

    NSMutableArray *newArray = [NSMutableArray array];
    for (int i=0;i<[array1 count];i++)
        [newArray addObject:[NSNumber numberWithInt:[[array1 objectAtIndex:i] intValue]+[[array2 objectAtIndex:i] intValue]]];
        //If you're using Mountain Lion, then you can use the following 
        //[newArray addObject:@([array1[i] intValue]+[array2[i] intValue])];
    

    Edit:

    If you have more than 1 array, then

    int numArrays = 3;
    NSArray *arrayOfNum = //An array of arrays that contains all the numbers
    NSMutableArray *newArray = [NSMutableArray array]
    for (int i=0;i<[array1 count];i++)
    {
        int total = 0;
        for (int x=0;x<numArrays;x++)
            total+=[arrayOfNum[x] intValue];
        [newArray addObject:@(total)];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an NSArray consisting of NSNumbers and I want to convert this to
So, basically I have an NSArray . I want to get an array with
I have NSArray and I want to remove duplicates from it. I know that
I have an NSArray full of NSDictionary object. This structure is built from a
I have a NSArray containing objects. I want to create a secondary NSArray containing
I want to send out an NSArray, so I have to write it to
I have two NSArray objects and I want to add the two arrays together
I'm not even sure of this is possible, but if it is, it could
Currently I have: NSArray* array = [NSArray arrayWithObjects:@"auth.login",@"username",@"password", nil]; NSData* packed_array = [array messagePack];
I have an NSArray with over 4.000 CGPoints [NSArray arrayWithObjects: [NSValue valueWithCGPoint:CGPointMake(213, 30)], ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.