Your playground is most likely created for the iOS platform - Cocoais the basis for the target OS X, and its iOS copy is - UIKitand both contain APIs associated with the user interface (for the corresponding platform). Try changing this to:
import UIKit
and it should work.
Foundation - , API-, NSString, NSDate, NSDateFormatter. Cocoa UIKit, reimport, 2.
, , Foundation, UIKit Cocoa.