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

  • Home
  • SEARCH
  • 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 8051177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:14:49+00:00 2026-06-05T07:14:49+00:00

Since I use NSInteger arrays frequently, I wrote a category for NSArray (and one

  • 0

Since I use NSInteger arrays frequently, I wrote a category for NSArray (and one for NSMutableArray too) that adds methods such as integerAtIndex:, arrayByAddingInteger:, etc. The methods take care of wrapping/unwrapping the NSInteger in an NSNumber object.

What I’m wondering is whether there is a way I can enhance my category so that I can do fast enumeration on the NSIntegers. I would like to be able to write:

NSArray* arrayOfIntegers;
    .
    .
    .

for(NSInteger nextInteger in arrayOfIntegers)
    {
    }

….so that “nextInteger” is pulled out of the NSNumber object behind the scenes. Can I do this?

  • 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-05T07:14:50+00:00Added an answer on June 5, 2026 at 7:14 am

    I doubt that there is a clean way of doing this with NSFastEnumeration, as it heavily depends on the nextObject method.

    But, you could do it in another way, by adding a block method for it:

    @interface NSArray (Integers)
    -(void)eachInteger:(void(^)(NSInteger))block;
    @end
    
    @implementation NSArray (Integers)
    -(void)eachInteger:(void(^)(NSInteger))block {
      for (NSNumber *num in self) {
        block(num.integerValue);
      }
    }
    @end
    

    That way, you could use it in your code in a similar way:

    NSArray *arr = [NSArray arrayWithObjects:[NSNumber numberWithInt:23],
                                             [NSNumber numberWithInt:42],
                                             nil];
    ...
    [arr eachInteger:^(NSInteger i) {
      NSLog(@"The int is %i", i);
    }];
    // =>
    //    The int is 23
    //    The int is 42
    

    Perhaps you might want to take a look at the NSArray categories on the Lumumba Framework, which happens to be written by me 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since I use jQuery 1.3+ all except one timed test is using that. The
Since I'm using Postgresql and can't use LINQ to SQL, I wrote my own
I have created my own class that extends CountDownTimer. Since I use it often,
Since beginning to use VB.NET some years ago I have become slowly familiar with
I use prototype since a long time, but for some reason I have to
I want to use L2E since it's very convenient to my company's apps, I
Since a week I use ToirtoiseSVN and AnkhSVN and GoogleCode and sourceforge.net as my
Since Google App Engine is a PaaS does it use any hypervisor? it is
I must use pkzip in my java program to zip (since standard java zip
Since I upgraded my iPhone to 5.1 I have been unable to use it

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.