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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:37:42+00:00 2026-05-31T01:37:42+00:00

So my problem is basically this, I’m parsing through a mutable array of numbers

  • 0

So my problem is basically this, I’m parsing through a mutable array of numbers and strings to try and find variables. I have a private helper method, which is working just fine, and differentiaties between operations (@”+”, @”-“, etc) and variables (@”x”, @”y”, etc). Problem is, the code in my else block below isn’t working. I get inside the else statement just fine with @”x” or @”y”, but the NSSet i’m trying to create isn’t working. I just keep NSLog(ging) “return variables is empty”. Any ideas?

+ (NSSet *)variablesUsedInProgram:(id)program
{

    NSMutableArray *stack;

    if([program isKindOfClass:[NSArray class]]){
        stack = [program mutableCopy];
    }

    NSSet *returnVariables = nil;

    for (int i=0; i<stack.count; i++) {
        if ([[stack objectAtIndex:i] isKindOfClass:[NSString class]]) {
            if ([self isOperation:[stack objectAtIndex:i]]) {
                continue;
            } else {
                returnVariables = [returnVariables setByAddingObject:[stack objectAtIndex:i]];
                if (returnVariables.count == 0) {
                    NSLog(@"returnVariables is empty");
                }
            }
        } 
    }

    return returnVariables;
}
  • 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-31T01:37:43+00:00Added an answer on May 31, 2026 at 1:37 am

    This is because you’re not initializing returnVariables. Change this line:

    NSSet *returnVariables = nil;
    

    to this:

    NSSet *returnVariables = [NSSet set];
    

    The -[NSSet setByAddingObject:] is an instance method, meaning it is to be called on an instance of NSSet. It isn’t meant to create a new set from scratch, rather it takes the existing set you call it on and creates a new set which is a copy of that set with an additional object added to it, and returns that new set.

    Even better, use an NSMutableSet:

    NSMutableSet returnVariables = [NSMutableSet mutableSet];
    
    // Inside your loop:
    [returnVariables addObject:[stack objectAtIndex:i]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem is basically this, in python's gobject and gtk bindings. Assume we have
This is basically a math problem, but very programing related: if I have 1
I have basically the same problem outlined in this question, however I am using
My problem is this: Basically if I try to commit a change to SVN
Sorry for the vague title, as I really can't explain this problem succinctly. Basically
Basically my problem stems from a desire to have the textbox portion be white,
My problem basically looks like this: module Foo class Bar def self.who self.class.to_s end
I have run into a blocking scenario and need help. The problem is basically
I have a method called -(IBAction)setPicker:(id) sender Basically this method substitutes a keyboard into
I have a javascript lib, basically this is how it is structured so far:

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.