I suggest you delve deeper in to the underlying issue, the problem you are really trying to resolve, and other solutions for that issue. Or at least, better understand how the OS utilizes swap space.
Many people assume, incorrectly, that SWAP space is only used when free RAM is needed. Generally speaking (I am not certain about the Linux kernel!), an OS with swap space will swap out blocks of RAM which it sees have not been recently accessed: Very few algorithms will check if the swap is needed because RAM is full, only if the RAM has not been recently accessed. Thus, if you leave the system idle for awhile, RAM which has not been accessed because the system has been idle and certain programs are not accessing parts of their memory space, the OS will still swap out parts of that RAM even when there is still plenty of free RAM.
This is illustrated by this question over on Ask Ubuntu, where the user experiences the OS swapping large parts of RAM to swap space while leaving their system idle for days--then experiences poor system performance for awhile after returning and using the system again and the OS is trying to restore used/accessed blocks of RAM which are once again being accessed regularly.
One approach, if you can use it, is to not use the SSD for swap space at all. In my desktop, I have an old 500GB non-SSD hard drive with a swap partition I use.
Another method would be a performance trade-off: Create a cron job for a script that runs every minute and checks RAM use. When RAM use is above 60%, it uses
swapon (with appropriate parameters) to use a swap file in case it is needed. When RAM use drops back below 40%, it then uses
swapoff to disable the use of the swap file and let the OS "drain" the swap back in to physical RAM. Of course, you will need a previously created and properly initialized swap file to enable/disable. (And make the thresholds different... If you set them both to the same value such as 50%, you will experience thrashing when the RAM use hovers between slightly above 50% and slightly below 50%. Fine tune the values to how you typically use the system.)
I am sure there are other methods and techniques used by others, as well. Likewise, as the use of SSD drives increases, the kernel algorithms will likely be modified to use SSD-based swap partitions less unless absolutely needed.