Most of the tutorials on recording and playing voice using AVFoundation in Swift focuses on iOS. The problem with this is that iOS utilizes AVAudioSession, which acts as an intermediary between your iOS app and the operating system, that is not supported on OS X.
This is a short GIST about how to record, save to file, and play audio input from OS X’s default mic under 100 lines of code.
Reference: https://github.com/jgorset/Recorder which I believe works well in iOS.