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