This article studies the control barrier function (CBF) guided tracking performance optimization for switched systems under iterative learning control (ILC). CBF is an effective method for handling control system state safety. If the safe set is designed as expected performance, and the unsafe set is not expected, then this may be a good choice for optimizing control system performance. We propose a tracking performance optimization method based on CBF to speed up the convergence of the tracking error. A safe set is used to describe the expected tracking performance, by utilizing CBF, safety is further transformed into a set of inequality conditions that constrain ILC controller gains, which ensures that the tracking error is always within the safe set. In addition, an event‐triggering mechanism (ETM) is considered to reduce unnecessary data transmission, and sufficient conditions for exponential stability of the tracking error of switched systems and ILC controllers design are obtained. Finally, a simulation example is given to verify the feasibility of the proposed method.