Hello good folks,
once again I need your help as I have stumbled across a seemingly easy issue
I can't wrap my head around at this hour (1am).
I have a NSMutableArray with 3 objects in it. I take an text input and check if it is in the array. If it is in the array I say good work and exit. If it is not in the array I ask if you would like to add it, and then try to add it with insertobjectatindex:0. but when I re-run the entire loop it is not found in the array.
I also tested this in an CLI app and get the same result from keyboard entry.
I do not re-start the app, I have set up an for loop to keep checking in an infinite loop until i solve this issue.
any advice would be greatly appreciated.
for clarification this is the code:
once again I need your help as I have stumbled across a seemingly easy issue
I have a NSMutableArray with 3 objects in it. I take an text input and check if it is in the array. If it is in the array I say good work and exit. If it is not in the array I ask if you would like to add it, and then try to add it with insertobjectatindex:0. but when I re-run the entire loop it is not found in the array.
I also tested this in an CLI app and get the same result from keyboard entry.
I do not re-start the app, I have set up an for loop to keep checking in an infinite loop until i solve this issue.
any advice would be greatly appreciated.
for clarification this is the code:
Code:
int a = 0;
while (a == 0) {
id RandomObject;
char namnet[10] = {0}; NSLog(@"\nPlease Enter Username\n"); scanf("%s", namnet);
RandomObject = [NSString stringWithUTF8String:namnet];
NSMutableArray *myArray = [NSMutableArray arrayWithObjects:@"Steve",@"Ben",@"John", nil];
//NSLog(@"%@ and %@",myString,[myArray objectAtIndex:1]);
if ([myArray containsObject:RandomObject]) {
NSLog(@"User is known!!");
}else {
id name;
name = RandomObject;
NSLog(@"unknown user!");
NSLog(@"\n Please add user!\n");
[myArray insertObject:name atIndex:0];
NSLog(@"%@",[myArray objectAtIndex:0]);
}
}
}
return 0;
}
Last edited: