For the formation achievement problem for swarm systems, an optimal control method with guaranteed-performance and switching topologies is proposed. Firstly, the mathematical description of the formation achievement problem with guaranteed-performance is established and a formation control protocol is designed. Secondly, sufficient conditions for swarm systems with time-varying formation are obtained by variable substitution and the stability of the system is analysed using the Lyapunov approach. Then, the formation controller is designed by solving the linear matrix inequality, and the mathematical expression of the upper bound of performance for the swarm system is given . Finally, a numerical simulation is provided to illustrate the effectiveness of the proposed control method.