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

Forquare1

macrumors newbie
Original poster
Jun 22, 2008
20
0
Hi all,

I'm new to XCode and Objective-C, coming from Eclipse and programming in Java.
After deciding to learn Obj-C, I thought I could test my knowledge by reprogramming some of my assignments. One such exersise was to create a caesar cipher (take a string, shift all the characters by a defined number).

I have some code which gets an NSString, and a number. I have then managed to convert the NSString to uppercase, pick out a char and shift that char.
Problems occur when I try to amend an NSMutableString.

Here's some of my code:

Code:
	/*set up variables*/
	int myShift = shift + 1;
	NSString *myText = text;
	NSMutableString *toReturn;
	unichar toProcess;
	
	myText = [text uppercaseString]; //make UPPERCASE
	
	
	for (int i = 0; i < [myText length]; i++) {
		toProcess = [myText characterAtIndex:i];
			
		if(toProcess < 'A'){
			break;
		}
		if(toProcess > 'Z'){
			break;
		}
		
		toProcess = toProcess + myShift;
		
		if(toProcess > 'Z'){
			toProcess = toProcess - 26;
		}
		
		NSLog(@"%C", toProcess); //This works!
		
		[toReturn appendFormat:@"%C", toProcess]; //This doesn't
	}

That last line I got from this thread, but it doesn't seem to work. I get this message:
2008-06-22 16:25:00.213 Encryption[1803:813] *** -[NSButton appendFormat:]: unrecognized selector sent to instance 0x12caf0

Thanks for any help :)

Ben
 

kpua

macrumors 6502
Jul 25, 2006
294
0
You never initialized toReturn, so its contents are just random bits, which happen to be a pointer to an NSButton instance.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.