Skip to content
Guest Big Announcement

[OBJ-C] Loop through an array?

Featured Replies

Hello I cant figure this out for the life of me I am attempting to remove all the users from the array by only actually removing one (so removing one person within the array would trigger the loop), I have tried for loops, while loops and everything as of now the code compiles, but it only removes the very first person in the array, and it wont remove the rest. (I guess I am trying to call the same function over and over again without actually removing the user manually)

%hook KikStanzaGroupRemoveUser

- (id)initWithUserJid:(id)arg1 fromGroup:(id)arg2 {

NSArray *allUsers = @[@"[email protected]", @"@[email protected]", @"[email protected]"];

for (int i = 0; i < allUsers.count; i++) {
NSString *user = [allUsers objectAtIndex:i];

if ([arg1 isEqualToString:user])
	arg1 = user;
	
	}
	
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"KEight Error"
	message:@"No users to purge or user selected is outside of hardcoded array!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
	[alert show];
	[alert release];
	return %orig;
	
}

%end

I am now lost, I don't know what to attempt next, I was thinking selectors but I am probably wrong

Solved by Guest

  • Solution
for(int i=0; i<[allUsers count]; i++){

//do stuff

}


int i;

for (i = 0;i <= allUsers.count; i++) {

NSString *user = [allUsers objectAtIndex:i];

NSLog(@"%@",user);

}

Updated by castix

 

int i;
for (i = 0;i <= allUsers.count; i++) {
NSString *user = [allUsers objectAtIndex:i];
NSLog(@"%@",user);
}

Thank you for posting what I just posted

Thank you for posting what I just posted

Without NSLog it will repeatedly delete all users

Delete user 1;

Delete user 1, Delete user 2;

Delete user 1, Delete user 2, Delete user3;

...

Without NSLog it will repeatedly delete all users

Delete user 1;

Delete user 1, Delete user 2;

Delete user 1, Delete user 2, Delete user3;

...

So are you implying that by having a NSLog, the for loop wouldn't delete all users? Wouldn't it just run NSLog and then go on to do what it was going to do?

And why don't you just user allUsers

So are you implying that by having a NSLog, the for loop wouldn't delete all users? Wouldn't it just run NSLog and then go on to do what it was going to do?

And why don't you just user allUsers

It would also delete all users but save a lot of performance since the NSLog checks if the user is already deleted or not to avoid exponential delete

Create an account or sign in to comment

Featured Content

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.