There's plenty to say about this topic, but here are a few thoughts. Use of typical swearing, obscenity, etc. has the effect, immediately, for me, of making a piece of writing reek of our own time and culture. If an author wants to write about some ancient realm or farflung planet, she or he had better not use expressions I'd hear on any urban street today.
Very well, an author might say, I'll borrow archaic terms (if I'm writing fantasy) or invent some (if I'm writing space fantasy). So I have a vague memory of L. Sprague de Camp, when he was writing fantasies in the 1970s, borrowing old expressions for the pudenda, etc.; these distracted me from the story because I felt that de Camp was showing off a bit by reviving words that were naughty in Chaucer's or Shakespeare's time. A similar type of distraction would, for me, occur if I were reading a science fiction story and the author evidently had concocted such terms of scandal and abuse. I would find myself to be out of the story and thinking about the author. The narrative spell would be broken.
So, pragmatically, there is a problem with using obscenity and vulgarity an imaginative fiction.
With regard specifically to swearing, that is, misusing the name of a god or God -- I don't think anyone is much bothered by Conan's "By Crom!" kind of thing, although, for me, it comes across as kind of a grab at a cheap "verisimilitude" -- i.e. I think of the author as having put that in as a quick was to try to imply a little "world-building," probably not very convincingly. Because it sounds a bit hokey, I might, myself, if writing a Conan story, write something like: "The Cimmerian cursed the Hyrkanian by his gods and reached for his dagger," etc. To me that sounds more threatening than the sort of thing Howard wrote, along the lines of, "Conan reached for his dagger. 'By Crom, Hyrkanian, I'll feed your guts to the vultures,'" etc.
As for the issue of swearing in the name of, or at, the God in whom some readers, like me, might actually believe. I appreciate it when authors, movie-makers, etc. generally refrain from it.
Finally: I've read a great deal of fiction from before the 1920s. Obscenity, vulgar sexual references, etc. are generally completely absent from Dickens, Elizabeth Gaskell, Trollope, the Brontës, Tolstoy, Stevenson, Dostoevsky, Jane Austen, Gogol, James, Aksakov, Turgenev, George Eliot, Chekhov, &c. Their work is nevertheless regarded as rich in human interest. Outbursts of religious language are limited to "My God!" and the like. Dostoevsky is able to get across the suicidal Smerdyakov's blasphemous final gesture without quoting him.