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 956849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:36:18+00:00 2026-05-16T00:36:18+00:00

New to Cocoa, and seem to be missing something. What is the most elegant/idiomatic

  • 0

New to Cocoa, and seem to be missing something.

What is the most elegant/idiomatic way to obtain the first x elements of an NSArray as another NSArray? Obviously I can iterate through them and store them manually, but it seems like there has to be a more standard method of doing this.

I was expecting there to be an -arrayWithObjectsInRange: or something similar, but don’t see anything…

NSArray* largeArray...// Contains 50 items...

NSArray* smallArray = // fill in the blank     

// smallArray contains first 10 items from largeArray

Thanks!

  • 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-05-16T00:36:19+00:00Added an answer on May 16, 2026 at 12:36 am

    You can use subarrayWithRange:.

    NSArray *smallArray = [largeArray subarrayWithRange:NSMakeRange(0, MIN(10, largeArray.count))];//MIN() used because array must be larger than or equal to range size, else exception will be thrown
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Cocoa, and working my way through Hillegass's book. I'm having trouble
I'm Delphi programmer and very new to Cocoa. at first I tried this :
New to Cocoa and Objective-c. Do I need getters and setters if I'm depending
Brand new to Cocoa and I'm trying to figure out how to copy an
I am new to cocoa touch programming. Is there a widget/control in cocoa touch
I am new to Cocoa and wanted to develop an app which can use
I'm new to Cocoa and kinda trying to create a timer. I'm trying to
I'm quite new to Cocoa and I am trying to setup a table view
I'm fairly new to Cocoa. I was talking to my brother, who's put together
I'm very new to Cocoa for MacOSX, but I can't help but feel like

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.