# Swap test vs measurement in a specific basis

I have two states $$|\psi\rangle$$ and $$|\phi\rangle$$. The swap test allows to estimate $$|\langle \psi | \phi \rangle|^2$$ by using the controlled SWAP gate and a couple of Hadamard gates. To obtain the estimate we repetitively measure the first qubit in the computational basis.

I don't understand why the swap test is necessary if we could just repetitively measure $$|\psi\rangle$$ in a basis $$\{|\phi\rangle, |\phi^{\perp}\rangle\}$$ and get an estimate of $$|\langle \psi | \phi \rangle|^2$$?

Is this test useful because it preserves both $$|\psi\rangle$$ and $$|\phi\rangle$$? Or measuring in the computation basis is easier than measurement in $$\{|\phi\rangle, |\phi^{\perp}\rangle\}$$?

Thank you.

When applying the swap test, once you are provided the states $$|\psi\rangle, |\phi\rangle$$, you need no additional information about the systems to estimate $$|\langle \psi | \phi \rangle|^2$$.
With the projective measurement technique, you need to implement a measurement $$\{|\phi\rangle\langle \phi|, I - |\phi\rangle\langle \phi|\}$$ in order to estimate $$|\langle \psi | \phi \rangle|^2$$, which involves having some knowledge about $$|\psi\rangle$$ or $$|\phi\rangle$$ or how the states are prepared. For example, this measurement is easy to perform is if you are provided $$|\psi\rangle$$ and also given the ability to implement a unitary $$V^\dagger$$ where $$V$$ satisfies $$|\phi\rangle = V |0\rangle$$. In this case, you define your measurements as \begin{align} |\phi\rangle\langle \phi| &= V |0\rangle \langle 0| V^\dagger \tag{1} \\ I - |\phi\rangle\langle \phi| &= V \left(I - |0\rangle \langle 0|\right) V^\dagger \tag{2} \\&= V\left(\sum_{x\in\{0,1\}^n\backslash0} |x\rangle \langle x|\right)V^\dagger\tag{3} \end{align}
This form of the measurements highlights that after applying $$V^\dagger$$ to $$|\psi\rangle$$, the projectors represent computational basis measurements where the probability of observing "0" is $$p(0) = |\langle \psi | \phi \rangle |^2$$. But again, this relied on the ability to implement $$V^\dagger$$, which is not guaranteed.