I have a NSArray with possibly hundreds of elements. I want to remove every element but the 20 first ones. Ideas?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
If your array is an NSArray, then you can’t remove objects since it’s immutable. You’ll need to do something like Neo’s answer. If your array is an NSMutableArray, you can use the following line to get the first 20 items: