All perfect praise be to Allah, the Lord of the worlds. I testify that none is worthy of worship except Allah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
If one does something that he believes invalidates the fast but it was not as such in fact, like swimming for example, and he actually did it while thinking that it beaks his fast, then he is considered to not be fasting because what he did eliminates and contradicts the intention of fasting. This is a matter that invalidates the fast according to those who adopt the opinion that rejecting the intention of fasting invalidates it. This is what we adopt out of caution for the religion. The questioner should fast a day in order to make up for that day. This is only because the intention is a pillar of fasting, as in the Hadeeth: “The reward and validity of deeds are only determined according to intentions.” [Al-Bukhari] This confirmation indicates the invalidity of deeds if intentions are invalid.
Allah knows best.