From here
If you borrow a low-rate currency to buy a high rate currency, you should earn interest. If you do the opposite, you pay.
Let's say you are trading USD/JPY. If you want to long USD/JPY what you are in fact doing is buying USD with your JPY. However, since you don't actually have any JPY, you need to borrow it first and use a part of your margin as collateral for that loan. Once you have borrowed the necessary amount of JPY, you can use it to buy USD and there is your trade. Now, since you actually borrowed the JPY, you have to pay interest on that loan at the prevailing rate until you have paid back the loan (closed your trade), and since you are holding USD, you are being paid interest on that sum for as long as you are holding it. The difference between what you are paying and what you are collecting in interest is what your swap will come out to be.