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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:55:52+00:00 2026-05-16T17:55:52+00:00

I have some numbers stored in an NSString. Is it safe to extract them

  • 0

I have some numbers stored in an NSString.

Is it safe to extract them into an NSInterger like this :

NSString* path = [[NSBundle mainBundle] pathForResource:@"rugby" ofType:@"txt" inDirectory:@""];
NSString* data = [NSString stringWithContentsOfFile:path encoding: NSUTF8StringEncoding error: NULL];
NSMutableArray *statsHolder = [[NSMutableArray alloc] init];

[statsHolder addObject:[NSString [data substringWithRange:NSMakeRange(0, 3)] integerValue]];

Am i misunderstanding how to do this or would that be valid?

My second question is about objects. I am trying to copy objects. I am worried that if i copy an object into an array then later change the value contained in the object that was copied into the array, the object thats in the array will also have the value changed as it is just a pointer to the original object. I demo what i mean in code as its hard to make clear.

    else if ([newString isEqualToString: newline])
    {
        [statsHolder addObject:[[data substringWithRange:NSMakeRange(i-rangeCount, rangeCount)] integerValue]]; 
        commaCount=0;
        rangeCount=0;
        Card  *myCard = [[Card alloc] init];
        myCard.name = nameHolder;
        myCard.information = infoHolder;
        for (int x = 0; x < [statsHolder count]; x++)
             {
                 [myCard.statsArray addObject:[statsHolder objectAtIndex:x]];   
             }

        [deckArray addObject:myCard];       
        [myCard autorelease];
        [statsHolder removeAllObjects];

    }

You can see above I am filling an object called Card *mycard and then copying this into my NSMutableArray *deckArray.

NSString *nameHolder = @"";
NSString *infoHolder = @"";
NSMutableArray *statsHolder = [[NSMutableArray alloc] init];

Are my vars to hold the data while i collect it, before there is enough to populate the Card object and copy it into the array.

So my question is.. Will my all the Card objects stored in the array all point to the last values that were contained in

NSString *nameHolder = @"";
NSString *infoHolder = @"";
NSMutableArray *statsHolder = [[NSMutableArray alloc] init];

Because of the way arrays and pointers work?

Sorry for asking a big complicated question. 🙂

-Code

  • 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-16T17:55:53+00:00Added an answer on May 16, 2026 at 5:55 pm

    The integerValue method is a perfectly fine way to convert a string to an integer. Another way, especially if you plan on storing multiple ints in a string (perhaps separated by a comma), is NSScanner.

    NSScanner *scanner = [NSScanner scannerWithString:someString];
    
    NSInteger number1, number2;
    
    [scanner scanInteger:&number1];            // Copy the first int
    [scanner scanString:@"," intoString:NULL]; // Skip the comma
    [scanner scanInteger:&number2];            // Copy the second int
    

    You need to wrap your number in some kind of object before putting it into an array. NSNumber is designed for this:

    [myArray addObject:[NSNumber numberWithInteger:number1]];
    

    Finally, what happens when you set properties on your Card class depends on how you declared the properties or wrote the methods. When it comes to strings, it’s usually a good idea to copy them:

    @interface Card : NSObject
    {
    // …
    }
    @property (nonatomic, copy) NSString *name;
    @end
    

    Now, when you card.name = xyz, the card will store a copy of xyz. If the original is modified or released, it won’t affect your card’s copy of the string.

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

Sidebar

Related Questions

I have some street numbers stored as VARCHARs but I want to sort them
I have some numbers of different length (like 1, 999, 76492, so on) and
Does anyone have some numbers on this? I am just looking for a percentage,
I have some numbers stored in a std::vector<int> . I want to find which
I have a some numbers stored in a Integer called mode , but I
I have numbers stored in a database, and some have a zero as their
I have some client-side validation against a text box, which only allows numbers up
Some background: In Germany (at least) invoice numbers have to follow certain rules: The
I still have a large number of floppies. On some of them there probably
I have some decimal numbers in a text file represented in exponential form Eg:

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.