Your master services agreement with your clients should define this in your intellectual property assignment and/or licensing clauses. To not have this defined is risky business practice.
I currently do user experience consulting, and my current MSA (the standard AIGA MSA) has a full assignment clause, which reads, in part:
Upon completion of the Services, and expressly subject to full payment of all fees, costs and expenses due, Designer hereby assigns to Client all right, title and interest, including without limitation copyright and other intellectual property rights, in and to the Final Art.
There are other possible choices depending on the project, including limited-use licensing clauses:
The rights granted to Client are for the usage of the Final Art in its original form only. Client may not crop, distort, manipulate, reconfigure, mimic, animate, create derivative works or extract portions or in any other manner, alter the Final Art.
In both cases, any original inventions (e.g. a new design pattern) are only licensed; they are not assigned.
When I did development consulting (many years ago), our rates changed depending on whether or not we could reuse what we created. It was all in the contracts.
One thing to remember is that full assignment of all code literally means you need to wipe it from your systems, and do full knowledge transfer including how to build it, how to upload it to the App Store, etc. If they don't have a development team, that's probably pretty risky for them.