Aftershocks are a sequence of earthquakes that happen after a larger mainshock on a fault. Aftershocks occur near the fault zone where the mainshock rupture occurred and are part of the "readjustment process” after the main slip on the fault. Aftershocks become less frequent with time, although they can continue for days, weeks, months, or even years for a very large mainshock.
A swarm, on the other hand, is a sequence of mostly small earthquakes with no identifiable mainshock. Swarms are usually short-lived, but they can continue for days, weeks, or sometimes even months. They often recur at the same locations. Most swarms are associated with geothermal activity.