Pop back multiple viewcontrollers

I sometimes find myself creating applications that have a Home view and all other views should allow the user to directly return to this Home view. I don't just want to push a fresh copy of the Home view on the navigation stack and I can't guarantee that the previous view will be the home so [self.navigationController popViewControllerAnimated:YES] is gone. I use the below method to loop through the navigation stack until I find the already existing view controller and pop back to this

	

-(void)homeButtonPressed:(id)sender{
        NSArray *navArray = [self.navigationController viewControllers];
			
		for (int x = 0; x < [navArray count]; x++) {
				
			UIViewController *viewController = [navArray objectAtIndex:x];
				
			if ([viewController isKindOfClass:[HomeViewController class]]) { //change HomeViewController to your intended target
				[self.navigationController popToViewController:viewController animated:YES];
			}
		}			
}