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:
That last line I got from this thread, but it doesn't seem to work. I get this message:
Thanks for any help
Ben
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