Restoring your iPhone to its factory settings will wipe it completely clean, removing spyware and other malware in the process. But unless you backed up your iPhone prior to the infection, a factory reset will result in all your data being lost. Performing a factory reset is a last-resort, and not a substitute for a malware removal tool if you think your phone may have been hacked.