Because Spain is a member country of the European Union (EU), you cannot apply for Swiss unemployment benefits upon moving to Switzerland. As a rule, if you have been employed in an EU or EFTA member country and then terminate your employment for any reason (due to a move, for example), you must apply for unemployment benefits in the country in which you were employed.
On the other hand, if you were employed in a non-EU/EFTA country, you can apply for Swiss unemployment benefits within 1 year of returning to Switzerland. The key requirements are that you lived in a non-EU/EFTA country for at least 12 months and were employed in that country for at least 12 months within the past 2 years. You must provide a statement from your foreign employer which clearly states the length of your employment period.