Jump to content

Looping through an NSArray? + calling headers?!


11 posts in this topic

Recommended Posts

Posted

Hey So im trying to Loop through an NSArray I created and i keep coming back with 

 

error: unused variable 'jidd' 

 

here is my code.

 

 

%hook KikStanzaChangeGroupName


- (id) initWithGroup:(id)group andNewName:(id)name
{
NSArray *jid = @[@"[email protected]", @"[email protected]"];


for (int i = 0; i < jid.count; i++)
{
  NSString *jidd = jid[i];
      group = @"%@", jidd;
  }
 return %orig;
}


%end

could someone tell me what I am doing wrong/fix it?

 

I was thinking that i needed a .m or .h files but im not 100% positive.

 

 

Okay so the second question I have is, how would I call another header within a header? what i mean is this. If I for example, did

 

%hook CoreDataConversationManager


- (void) sendTextMessage:(id)command withRenderInstructionSet:(id)arg1 toConversation:(id)arg2 isSuggestedResponse:(BOOL)arg3
{

  if ([command isEqualToString:@"$ChangeName"]) command = @"new name";
return %orig;
}


%end

okay so if I typed out $ChangeName and clicked enter, it would do the same action as above (KikStanzaChangeGroupName) and change the name without actually having to go to that ChangeGroup Name ViewController and clicking save.

 

Posted (edited)

It's quite simple, you used the wrong accessor method.

To get the index of an item in an array, it makes more sense to use the "objectAtIndex:" method :)

%hook KikStanzaChangeGroupName

- (id) initWithGroup:(id)group andNewName:(id)name
{
NSArray *jid = @[@"[email protected]", @"[email protected]"];

for (int i = 0; i < jid.count; i++)
{
  NSString *jidd = [jid objectAtIndex:[NSNumber numberWithInt:i]];
      group = @"%@", jidd;
  }
%orig;
}


%end
Updated by KingRalph
Posted

 

It's quite simple, you used the wrong accessor method.

To get the index of an item in an array, it makes more sense to use the "objectAtIndex:" method :)

%hook KikStanzaChangeGroupName

- (id) initWithGroup:(id)group andNewName:(id)name
{
NSArray *jid = @[@"[email protected]", @"[email protected]"];

for (int i = 0; i < jid.count; i++)
{
  NSString *jidd = [jid objectAtIndex:[NSNumber numberWithInt:i]];
      group = @"%@", jidd;
  }
%orig;
}


%end

https://gyazo.com/cf12bca73e6dbab40042f119db4c9746 

 

I copied and pasted what you did and I got this :S?

Posted

The errors are related to type casting and stuff :3

 

Do this:

%hook KikStanzaChangeGroupName

- (id) initWithGroup:(id)group andNewName:(id)name
{
NSArray *jid = @[@"[email protected]", @"[email protected]"];

for (int i = 0; i < jid.count; i++)
{
  NSString *jidd = [jid objectAtIndex:(NSUInteger)[NSNumber numberWithInt:i]];
      group = @"%@", jidd;
  }
%orig;
}


%end

Posted

 

The errors are related to type casting and stuff :3

 

Do this:

%hook KikStanzaChangeGroupName

- (id) initWithGroup:(id)group andNewName:(id)name
{
NSArray *jid = @[@"[email protected]", @"[email protected]"];

for (int i = 0; i < jid.count; i++)
{
  NSString *jidd = [jid objectAtIndex:(NSUInteger)[NSNumber numberWithInt:i]];
      group = @"%@", jidd;
  }
%orig;
}


%end

that seemed to fix one, it still says the group = jidd is an unused expression... so would I do this?:  [NSString stringWithFormat:@"%@", jidd]

Posted

that seemed to fix one, it still says the group = jidd is an unused expression... so would I do this?:  [NSString stringWithFormat:@"%@", jidd]

Nope. You could ignore it (if it's not fatal) or you could do this:

 

%hook KikStanzaChangeGroupName

- (id) initWithGroup:(id)group andNewName:(id)name
{
NSArray *jid = @[@"[email protected]", @"[email protected]"];

for (int i = 0; i < jid.count; i++)
{
  NSString *jidd = [jid objectAtIndex:(NSUInteger)[NSNumber numberWithInt:i]];
      group = @"%@", jidd;
  }
%orig;
}


%end 
Posted

 

Nope. You could ignore it (if it's not fatal) or you could do this:

 

%hook KikStanzaChangeGroupName

- (id) initWithGroup:(id)group andNewName:(id)name
{
NSArray *jid = @[@"[email protected]", @"[email protected]"];

for (int i = 0; i < jid.count; i++)
{
  NSString *jidd = [jid objectAtIndex:(NSUInteger)[NSNumber numberWithInt:i]];
      group = @"%@", jidd;
  }
%orig;
}


%end

 

Hey, so I made this, now it only does the first one in the array, how would I make it loop so it is equal to the first one and then the second??

 

%hook KikStanzaChangeGroupName

-(id) initWithGroup:(id)group andNewName:(id)name
{
    NSArray *verified_users = @[@"[email protected]", @"[email protected]"];

    for (int i = 0; i < verified_users.count; i++) {
group = [verified_users objectAtIndex:i];
}
return %orig;
}
%end

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines