In the Gamemastery Guide advice for building creatures, there is a Swarm template with the following text:
Traits size based on the entire mass, usually Large or bigger
HP typically low; Immunities precision, swarm mind; Weaknesses area damage, splash damage; Resistances physical, usually with one physical type having lower or no resistance
Precision damage is a specific damage type, and is explained in the core rule book here:
Precision Damage
Sometimes you are able to make the most of your attack through sheer precision. When you hit with an ability that grants you precision damage, you increase the attack’s listed damage, using the same damage type, rather than tracking a separate pool of damage. For example, a non-magical dagger Strike that deals 1d6 precision damage from a rogue’s sneak attack increases the piercing damage by 1d6.
Some creatures are immune to precision damage, regardless of the damage type; these are often amorphous creatures that lack vulnerable anatomy. A creature immune to precision damage would ignore the 1d6 precision damage in the example above, but it would still take the rest of the piercing damage from the Strike. Likewise, since precision damage is always the same type of damage as the attack it’s augmenting, a creature that is resistant to non-magical damage, like a ghost or other incorporeal creature, would resist not only the dagger’s damage but also the precision damage, even though it is not specifically resistant to precision damage.
So swarms are immune to sneak attack, and other similar effects with the precision trait. They are also resistant, but not immune, to most other physical attacks.
However there are no targeting restrictions as there was in PF1. I would hazard that this change was, at least in part, made because in PF1, a CR 0 swarm could prove unusually and unpredictably deadly to a poorly prepared group of low level players (due to being effectively invincible against that group).
As a result, attacking a swarm with a sword is entirely possible, but not generally as effective as attacking it with Fire Ray, and very much less effective than attacking it with an area of effect or splash damage spell, such as the acid splash cantrip, or an alchemist's bombs.