Swordsmen are trained in the barracks, but you need a smithy first before the option appears.
Each unit takes 30 clay, 30 wood and 70 iron, and consumes one farm population. The heavy iron cost is the thing to plan around — swordsmen are strong defenders but will eat your iron supply quickly if you train in bulk.
Once the smithy is up, the swordsman entry appears in the barracks automatically. No further unlock is needed.