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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:43:48+00:00 2026-06-09T10:43:48+00:00

I feel like I have read many (simple) examples that do exactly what I

  • 0

I feel like I have read many (simple) examples that do exactly what I am trying to do. I just cannot seem to get this to work. I need a second eye on my code, and I don’t have anyone around, so pardon me if this seems very simple… The code compiles without a problem. Thank you!

@implementation Engine
- (id) initWithInventory: (NSString *) path {
    if (self = [super init]) {
        NSString *contents = [NSString stringWithContentsOfFile:@"ingredientList.csv" encoding:NSASCIIStringEncoding error:nil];

        NSLog(@"%@",contents); // This yields the contents of the file appropriately

        NSArray *lines = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
        NSRange ingredientRange = {0,96}; // This is done because I want to omit the last element of the array... the 97th is an empty string caused by the end of file newline character.  I know it's bad coding...

        NSEnumerator *enumerator = [[lines subarrayWithRange:ingredientRange] objectEnumerator];
        NSString *curString;
        NSArray *ingredientElements;
        NSRange activeEffectRange = {1,4}; // Element 0 will be the key, elements 1-4 are the array to be stored.

        while (curString = [enumerator nextObject]) {
            ingredientElements = [curString componentsSeparatedByString:@","];
            Ingredient *theIngredient = [[Ingredient alloc] initWithName:[ingredientElements objectAtIndex:0] andActiveEffects:[ingredientElements subarrayWithRange:activeEffectRange]];
            NSLog(@"%@",[theIngredient ingredientName]);
            NSLog(@"%@",[theIngredient activeEffects]); //These both print out correctly.

            NSString *theName = [theIngredient ingredientName];
            [allIngredients setObject:theIngredient forKey:theName];
            NSLog(@"%@",[allIngredients objectForKey:[theIngredient ingredientName]]); // ***This yields (null)***
        }
    }
    return self;
}

EDIT: I should add, that allIngredients is an instance variable of the class being initiated, so it is defined properly as an NSMutableDictionary:

@interface Engine : NSObject {
    NSMutableDictionary *allIngredients;
}
- (id) initWithInventory: (NSString *) path;
@end
  • 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-09T10:43:49+00:00Added an answer on June 9, 2026 at 10:43 am

    Where are you creating allIngredients? You’ve declared it, but you haven’t allocated it before you use it.

    allIngredients = [[NSMutableDictionary alloc] init]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question that I just don't feel like I've found a satisfactory
I hope this hasn't already been answered, but I feel like I have read
I feel like this must have been asked before, but I've looked at Knockout
I feel like this is quite delicate, I have various folders whith projects I
I feel like I've entered the Twilight Zone. I have a Grails form that
I have read that it is a good practice to not use too many
Ok, I feel like a total idiot. I have read the docs and still
This is really starting to piss me off. I feel like I have tried
1) I have read many times about undefined behavior in C. That is about
I feel like I have enough experience with CI to finally start fooling around

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.