简体   繁体   中英

int to NSUINteger conversion issue

i have a situation like this. i want to remove some object in a particular index in a mutable array. so i have a method for do that by passing the index. but it takes NSUInteger as a parameter. but i got an integer value as the index. when i call my method, the parameter value is null.. below is my code

for (int x=0; x<tempAry.count; x++) {

                NSArray* temp = [tempAry objectAtIndex:x];

                NSString* appoinment = [NSString stringWithFormat:@"%@",[temp valueForKey:@"AppointmentId"]];

                if ([appoinment isEqualToString:appoinmentID_for_rejct]) {

                    //attention here
                     NSUInteger* index = (NSUInteger*)x;
                    [TableViewController removeIndexfromDuplicate:index];

                }
            }

here the index got null..how can i fix this.? the index should not be null.. because x is not a null value..please help me

What you did see here (Converted an integer to pointer value, is there any specific reason to do ???):

//attention here
NSUInteger* index = (NSUInteger*)x;
[TableViewController removeIndexfromDuplicate:index];

It should be like this:

NSUInteger index = x;
[TableViewController removeIndexfromDuplicate:index];

Or simply use x as [TableViewController removeIndexfromDuplicate:x];

* Side Note: Follow good naming convention. TableViewController looks like a class!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM