If you cast Swerve on a spell that targets a spell on the stack (like Cancel does, for example), you can't change that spell's target to itself. You can, however, change that spell's target to Swerve. If you do, that spell won't resolve when it tries to resolve because Swerve will have left the stack by then.