Your playground is most likely created for the
iOS platform -
Cocoa is a framework
for the OS X target, and its iOS counterpart is
UIKit, and both contain user
interface related APIs (for the respective
platform). Try changing that to:
and it should work.
Foundation is a framework containing several
APIs, such as NSString, NSDate, NSDateFormatter.
It is already included in Cocoa and UIKit, so you
don't need to reimport if already importing one of
However, the code you posted in your question
uses classes from Foundation only, so there's no
need to import either UIKit or Cocoa.