First of all, it will be helpful to understand that the software of Apple devices are really secure. There can be a rare chance of your device getting affected by a virus. In case you suspect a virus on your iPhone or mac , you can try to factory reset it. It can help in removing the virus. Additionally, if your device is misbehaving and the virus may not necessarily be the reason for this, then that problem should also get resolved by factory resetting your device.