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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:44:41+00:00 2026-05-20T15:44:41+00:00

Using an NSMutableArray ivar, I plan to write a class that acts like a

  • 0

Using an NSMutableArray ivar, I plan to write a class that acts like a stack and which objects of various types should be able to be retrieved from.

Whenever that stack threatens to run out of objects because almost all have yet been retrieved, it should automatically push new objects onto itself by fetching them from some sort of as-generic-as-possible “object emitter”. For example, there should be supplicant classes which return instances of NSImages or of NSString or any other imaginable types which should be put on the stack but each have to be treated in a separate way beforehand.

What would be the easiest pattern of “plugging in” those object emitting classes into my stack class? The stack class should not need to be aware of the object types it has to deal with, this is where some “helper classes” might set it – but I have no clue where their place would be. I tried Dynamic Creation using NSClassFromString but that just doesn’t feel quite right.

  • 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-20T15:44:41+00:00Added an answer on May 20, 2026 at 3:44 pm

    NSMutableArray is capable of storing any object. Unlike generic collections in Java, where data structures store instances of specific classes, Cocoa allows you to add anything to an NSArray. So, your pop method could simply remove the last object of the array, check to see if the size is smaller than some threshold, and then request new objects from supplier classes.

    For example:

    - (NSObject *)pop {
          NSObject *poppedObject = [mutableArray lastObject];
          [mutableArray removeLastObject];
          if ([mutableArray count] < SMALLEST_ALLOWABLE_STACK_SIZE) {
              for (MYContentProvider *provider in [self contentProviders]) {
                   [mutableArray addObjectsFromArray:[provider fetchContent]];
              }
          }
          return poppedObject;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that subclasses NSMutableArray. I init it using: MyClass class =
I am using a NSMutableArray to store some of the UIView objects that are
I'm using an NSMUtableArray to store some objects I created. but when I write
Before I roll my own Queue using NSMutableArray , I'd like to know if
I am trying to assign objects in an NSMutableArray using this code - (IBAction)variablePressed:(UIButton
In version 1.0 i am using NSMutableArray and inside that i am storing NSNumbers
I was using a NSMutableArray and realized that using a dictionary is a lot
I am developing one application. In that iam using the NSMutableArray for storing the
I am using the following code to write into a plist: NSMutableArray *d =
I'm using ARC and targeting iOS 5. I've declared an NSMutableArray ivar in one

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.