Is a 2x4 strong enough to hold up a porch swing?
There are several issues to consider - whether the 2x4 itself is strong enough to bear the load you're putting on it in the direction that you're loading it (so the grade/type of wood is important, not all 2x4's are created equal), whether the fastener/hook you use will overstress the wood in the 2x4 at the point where it attaches, and whether the load on the 2x4 will overstress/exceed the capacity of whatever it is that's attaching the 2x4 to whatever it is that it's attached to/supported by.

My unscientific, short answer is "no", I wouldn't depend on a 2x4 of unknown provenance to support the weight of 2 adults (or any number of children) + the weight of the swing, especially given wear &amp; degradation over time.

If it was a short run of 2x4 and the swing was attached really well and the 2x4 is attached really well to something strong, yeah, it'll probably work, but if it were my house/family involved, I'd look for a stronger way to hang the swing.