Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,216
1,030
I have everything set up to save to the array, but since NS(Mutable)Array's cant store int's, I have to convert my int to an NSNumber, this is where I am getting stuck. I can't figure out how to convert the int.

I tried:

Code:
(NSNumber *)numberWithInt:(scoreVar)100;
Code:
(scoreVar *)numberWithInt:(int)100;
Code:
(NSNumber *)numberWithInt:(int)100;

No luck though :(
 
Code:
NSNumber *yourNumber = [NSNumber numberWithInt:your_int_variable];

Should be what you're after. your_int_variable is the int variable.
 
Code:
NSNumber *yourNumber = [NSNumber numberWithInt:your_int_variable];

Should be what you're after. your_int_variable is the int variable.

When I do that, I get the following error when attempting to save it to the array:

"warning: passing argument 1 of 'setScoreName:' from distinct Objective-C type"

Here is my code for setting the array value:

Code:
		[newPerson setScoreName:scoreVarObj];
 
What exactly are newPerson and scoreVarObj?

newPerson where in the array my objects are stored. scoreVarObj is the NSNumber created by the int.

This is the full code of where I save the data

Code:
[newPerson setFirstName:@"Jeremy"];   NSLog(@"%@", newPerson.firstName);
		[newPerson setScoreName:scoreVarObj];     NSLog(@"%@", newPerson.scoreName);
		[personArray insertObject:newPerson atIndex:[personArray count]];

I have the encoding/decoding in its own NSObject File. Here is the implimentation of that file.

Code:
@implementation score
@synthesize firstName, scoreName;

- (id) init {
	if(self = [super init]) {
		firstName = [[NSString alloc] init];
		scoreName = [[NSString alloc] init];
	}
	
	return self;
}

- (void) dealloc {
	[firstName release];
	[scoreName release];
	[super dealloc];
}

- (id) initWithCoder:(NSCoder *)coder {
	firstName = [[coder decodeObjectForKey:@"firstName"] retain];
	scoreName = [[coder decodeObjectForKey:@"scoreName"] retain];
	return self;
}


- (void) encodeWithCoder:(NSCoder *)encoder {
	[encoder encodeObject:firstName forKey:@"firstName"];
	[encoder encodeObject:scoreName forKey:@"scoreName"];
}


@end
 
Ok, I fixed it so that everytime scoreName is mentioned, its mentioned as an NSNumber. But I get an error when I try to add the NSNumbers to the array. The error from the debugger is

Code:
2008-08-20 21:39:18.951 iDice[35026:20b] *** -[NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x465520
2008-08-20 21:39:18.951 iDice[35026:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x465520'
2008-08-20 21:39:18.952 iDice[35026:20b] Stack: (
    2461323595,
    2499793147,
    2461352778,
    2461346124,
    2461346322,
    817180501,
    11576,
    818069166,
    818076920,
    816177049,
    816209730,
    2472167774,
    2460826437,
    2460826872,
    829005112,
    829005309,
    816175835,
    816221412,
    8504,
    8358
 
The error is exactly what it is telling you- NSNumber does not have a function called isEqualToString, but you are trying to call isEqualToString on some NSNumber somewhere.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.