Is it possible to interchange countable unions and intersections?

Note that

$$x\in\bigcup_{i\in\omega}\bigcap_{n\in\omega}A_n^i$$

iff $\exists i\in\omega\,\forall n\in\omega\,(x\in A_n^i)$, while

$$x\in\bigcap_{n\in\omega}\bigcup_{i\in\omega}A_n^i$$

iff $\forall n\in\omega\,\exists i\in\omega\,(x\in A_n^i)$; the latter condition is on the face of it easier to satisfy, so you should look for an example in which

$$\bigcup_{i\in\omega}\bigcap_{n\in\omega}A_n^i\subsetneqq\bigcap_{n\in\omega}\bigcup_{i\in\omega}A_n^i\;.$$

Specifically, we might try to construct the sets $A_n^i$ so that there is some element $a\in A_n^n$ for all $n\in\omega$, which will ensure that

$$a\in\bigcap_{n\in\omega}\bigcup_{i\in\omega}A_n^i\;,$$

but so that there is no $i\in\omega$ such that $a\in A_n^i$ for all $n\in\omega$. This is easy: for each $i\in\omega$ make sure that $a\in A_n^i$ iff $n=i$. Thus, we can let

$$A_n^i=\begin{cases} \{a\},&\text{if }n=i\\ \varnothing,&\text{otherwise}\;. \end{cases}$$

Then

$$\bigcup_{i\in\omega}\bigcap_{n\in\omega}A_n^i=\bigcup_{n\in\omega}\varnothing=\varnothing\;,$$

but

$$\bigcap_{n\in\omega}\bigcup_{i\in\omega}A_n^i=\bigcap_{n\in\omega}\{a\}=\{a\}\;.$$


This is not possible in general. Even for finite unions and intersections you can have $$ (A_1\cap A_2)\cup(B_1\cap B_2)\subsetneqq(A_1\cup B_1)\cap(A_2\cup B_2). $$ Take for example $A_2=A_1^c$ (the complement in $X\neq\emptyset$) and $B_1=A_2,\;B_2=A_1$; then $$ A_1\cap A_2=B_1\cap B_2=\emptyset,\qquad A_1\cup B_1=A_2\cup B_2=X. $$