View Full Version : Why won't the error go away?

Dec 6, 2009, 07:33 AM
I had numerous errors about how I was trying to make integers from pointers without casting them. I was able to fix all of them except this one, for which the error was phrased slightly differently.

I had this initially:
[classes replaceObjectAtIndex: renamingClass withObject: addClassName.text];

but it was generating an error (and letting your errors pile up is a poor choice, it'll be much easier to find the one that crashes your program if you don't let them.)

So I changed it to this:
[classes replaceObjectAtIndex: (NSUInteger *) renamingClass withObject: addClassName.text];

But both of them insisted that
warning: passing argument 1 of 'replaceObjectAtIndex:withObject:' makes integer from pointer without a cast

classes is an NSMutableArray
renamingClass is an NSUInteger
addClassName is a UITextField
addClassName.text is an NSString

Dec 6, 2009, 08:38 AM
Instead of using replaceObjectAtIndex try this:

[classes removeObjectAtIndex:index];
[classes insertObject:object.text atIndex:index];
Also, index could be an int or an NSInteger, not necessarily NSUInteger. Try using one of those.

Dec 6, 2009, 08:43 AM
Why is "renamingClass" a NSUInteger? That's an exceptionally odd name for an integer variable. Can you show use more code, specifically where you declare and assign a value to this variable?

Dec 6, 2009, 12:52 PM
An (NSUInteger *) is a pointer, not an integer.

Dec 6, 2009, 01:11 PM
There's no way that renamingClass is declared as just a NSUInteger. Show us your code.

Dec 6, 2009, 01:46 PM
Here's more of the code:
From the header, my declaration of renamingClass:
NSUInteger *renamingClass;

Here's a method for when someone wants to rename a table cell... they would hit the edit button, then hit the table cell they want to rename.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
if (indexPath.section == 1 && tableView.editing == YES)
renamingClass = (NSUInteger *) indexPath.row;
renameClass = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Rename %@",[classes objectAtIndex:indexPath.row]] message:@"\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Rename", nil];
addClassName = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
addClassName.borderStyle = UITextBorderStyleRoundedRect;
addClassName.autocapitalizationType = UITextAutocapitalizationTypeWords;
addClassName.autocorrectionType = UITextAutocorrectionTypeNo;
addClassName.placeholder = [classes objectAtIndex:indexPath.row];
[renameClass addSubview:addClassName];
[addClassName becomeFirstResponder];
[addClassName release];
[renameClass setTransform:CGAffineTransformMakeTranslation(0.0, 85.0)];
[renameClass show];
[renameClass release];

addClassName is just a textfield that I decided to reuse since it's still in memory until the tableViewController is deallocated, and I know that users won't be adding and renaming classes at the same time.

Anyways, the UIAlert from before will eventually be dismissed at which point this method will be called:
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
if (alertView == renameClass)
[addClassName resignFirstResponder];
if (buttonIndex == 1)
[classes replaceObjectAtIndex: renamingClass withObject: addClassName.text];
[classes writeToFile: [[NSBundle bundleForClass:[self class]] pathForResource: @"Classes" ofType: @"plist"] atomically: NO];
[self.tableView reloadData];

Did you follow all that? I don't comment my code very much... I can add some more comments if you need them to follow it.

Luke Redpath
Dec 6, 2009, 01:58 PM
Your're using NSUInteger as a pointer everywhere; it is a primitive type, so stop using *.