Your question has two facets:
1) How to make guns, which are currently the dominant weapon of choice for most reasonably realistic scenarios, useless.
2) How to make swords, which are not a good weapon of choice even in the absence of guns, useful.
Let's tackle the first part. If you don't want to stretch imagination too far or introduce "weird physics", you have already suggested a reasonable answer already: scarcity of ammo.
If the engineering knowledge and manufacturing capability to mass produce ammunition is lost (such as in a post-apocalypse scenario), then the amount of bullets that can be fired in the world is finite. Depending on the type of apocalypse, it is likely that a sizeable portion of this stock will have been consumed already. So while you're left with still a sizeable stock, you are fully aware that the moment you run out, you're just a guy with a weird-shaped club in a world where everyone remembers how you used to bully them around with your gun. That way your gun becomes akin to what nuclear weaponry is today - a deterrent that can be effective only as long as you don't use it (or at least not wastefully use it).
You can also add in an external non-human danger, such as mutant beasts or whatever, that cannot be defeated by any other means except shooting it to death, and you have a reasonable further deterrent to wasting ammo against humans. In the end, if you have your story take place long enough after the apocalypse, you can simply state that they've run out of ammo and be done with it.
Now onto the second part. You figured out why your people don't use guns (at least not often, and not usually against each other). But why swords? Swords are not and were never the most practical type of weapon, no matter how cool they looked. Simple bows and crossbows are much more advantageous as a primary weapon in most situations because you can simply kill your enemy from afar, before they can close in on you, sometimes before they can even see you. Additionally even in a post-apocalyptic world they are not hard at all to manufacture and practice. But even if you need melee weapons (let's say that your story involves a lot of combat inside buildings, narrow corridors etc), a sword is not the ideal weapon of choice. A much better melee weapon would be a short spear, or you can go with an ax or hatchet that also doubles as a useful tool for hacking stuff out of the way (so you don't have to burden yourself with carrying more things). If we're talking about really narrow spaces, then even a sword becomes unwieldy, and you'd do much better with just wrapping metal around your knuckles and smashing your opponent's head in. Furthermore, even if you were really set on using swords, the problem becomes how to manufacture them. Without a dedicated blacksmith, you'd have trouble even making a proper sword, at least an effective one. They are far more "expensive" than spears or axes because they use a lot more metal, and therefore also harder to maintain, repair and replace if broken.
So... what do you have left? For me, there is only one "realistic" answer here. For whatever reason, after the apocalypse, there were a lot of swords lying around everywhere. People could just wander around a city for a few minutes and pick one up. Why? Maybe they were some shiny new thing developed to fight whatever caused the apocalypse. Maybe they were just in-fashion. Maybe your story takes place in a relatively small corner of the world, where a massive-scale fencing tournament was taking place. But for whatever reason, there is a sheer availability of swords. Everyone gets a sword and learns how to use it because they are just lying there, so it's much simpler than going to the trouble of making a new, more effective weapon (also the quality of the stuff is pre-apocalypse, so fairly good). As the weeks become months become years become decades, the use of swords becomes almost second nature to the survivors - at this point whatever society they rebuilt has become so effective in swordsmanship that swords are, actually, a pretty effective weapon in their hands, with the few remaining guns and precious stacks of ammo only found in the hands of leaders and tyrants.
Then, you can make an interesting plot point that some faction or other decides to experiment with weaponry (bows, spears etc) and finds themselves in an advantage, and the swordsmen who have been used all this time to sword-vs-sword battles have to adapt, etc.