Give the provided information, we can't know the speed of the swimmer, but let's suppose the swimmer swims at a speed of $v$ miles per hour. That is, if the water would not flow, she swims at $v$ miles per hour. Since the hat flows with the water, that means that as the swimmer swims upstream, the distance between the hat and the swimmer increases at exactly that $v$ miles per hour. So, swimming back, the swimmer decreases the distance with exactly $v$ miles per hour as well. So, if she swam upstream for one hour, it'll take that one hour to catch back up.
The key to solving this puzzle is therefore to look at the movement of the swimmer relative to the river as a 'whole'. That is, if we look at the movement of the swimmer relative to all of space, the swimmer goes through space at an enormous speed, since the swimmer is located n planet Earth, which hurtles through space at a good clip ... and our solar system moves at great speed relative to the center of our galaxy, etc. etc. So thinking about these kinds of things, we recognize that 'speed' is always relative to something. Now, here on Earth, and for day to day purposes, most of the time we think of and measure speed relative to the 'surface' of the Earth. Indeed, that's is exactly the perspective you are asked to take when asked the speed of the river: that's relative to the river bank, or bridge, or river bed, or anything that's in a 'fixed' position as far as the earth surface goes.
OK, but for solving this puzzle, it is better to take think about the movement of the hat and swimmer relative to the river as a whole. That is, we can think of the river as a kind of 'snake' that moves, as a whole, relative to the Earth's surface. However, how does the hat and swimmer move relative to this 'snake'? Well, relative to the river, the hat remains at a fixed position; it's as if it is 'attached' to the snake. The swimmer, however, moves with a certain speed relative to this river; think of it as 'crawling' along the skin of the snake. And we can assume that is the same relative speed as if the swimmer is in standing water, i.e. in a lake or pool. And, when the swimmer turns around, the swimmer moves at exactly that same speed relative to the river again, just in the opposite direction. So, thinking about it that way, it really is analogous to the situation where she would dive in a lake, lose the hat right where she dove in, swim for an hour into the lake, and then turns around: how long does it take to get back to the hat? An hour of course!