Not in Swift (yet). You can currently only record what you play on iOS if you use Audio Units to play synthesized midi, and Audio Unit callbacks have to be coded in C (at least partially).
Look into the documentation on the AUSampler Audio Unit. You may also need to use the AVAssetReader and AVAssetWriter APIs to convert PCM audio samples into an .m4a or .m4r format. It's not simple code. Tons of documentation on Apple's web site, but very little sample code appropriate to what you need.