I have an NSMutableArray in my code and I want to access the last element of that array and save the element in integer n variable. But n does not give me the correct value when I NSLog it, it gives me a garbage value.
for(int i=0;i<[array3 count];i++)
{
if(i==([array3 count]-1))
{
n = [array3 objectAtIndex:i];
}
}
NSLog(@"The id is=%d",n);
NSError *error;
NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d",n]];
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];