✔ 最佳答案
Usually we need to look at the auxiliary verb. Here I give you some examples:
Must use gerund: avoid, dislike, keep, mind, miss, practise...
Must use to-infinitives: agree, choose, need, plan, promise, want...
Can use both gerund and to-infinitives: begin, like, love, start, try...
The reason of why we must write "Swimming is my hobby" instead of "To swim is my hobby" is that, there is nothing related to gerund or to-infinitives. The word "Swimming" here act as a noun, so we cannot use "to swim (not a noun)" here.