Telefonica swings to net profit but Spanish business wilts