from your example, the first one is the base structure with the extension
struct xxx { } extension xxx { function yyy() {} }
the other is a structure with a built-in function.
struct xxx { function yyy() {} }
Imagine for some reason you cannot change the original structure, but you still want to be able to execute the yyy () → function, you can extend the class to call the yyy () function, without changing the class itself (or changing the path it behaves elsewhere in your program)
"Extensions can add new functions to a type, but they cannot override existing functions." (src: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Extensions.html )
-> Extensions are useful if you do not have access to the class, but you want to add some functions. Using extensions, you can separate classes and customize what the class can do as needed.
source share