The development of technologies for the additive manufacturing, in particular of metallic materials, is offering the possibility of producing parts with complex geometries. This opens up to the possibility of using topological optimization methods for the design of electromagnetic devices. Hence, a wide variety of approaches, originally developed for solid mechanics, have recently become attractive also in the field of electromagnetics. The general distinction between gradient-based and gradient-free methods drives the structure of the paper, with the latter becoming particularly attractive in the last years due to the concepts of artificial neural networks. The aim of this paper is twofold. On one hand, the paper aims at summarizing and describing the state-of-art on topology optimization techniques while on the other it aims at showing how the latter methodologies developed in non-electromagnetic framework (e.g., solid mechanics field) can be applied for the optimization of electromagnetic devices. Discussions and comparisons are both supported by theoretical aspects and numerical results.