What is the distinguishing feature of 'import Cocoa' and 'import Foundation' in Xcode Playground

This code works well on the playground

import Foundation

let stringDate : NSString = "1403437865"
let date = NSDate(timeIntervalSince1970:stringDate.doubleValue)

var outputFormat = NSDateFormatter()
outputFormat.locale = NSLocale(localeIdentifier:"ko_KR")
outputFormat.dateStyle = .MediumStyle
outputFormat.timeStyle = .MediumStyle
println("Result: \(outputFormat.stringFromDate(date))")

but this code does not work on Playground

import Cocoa

let stringDate : NSString = "1403437865"
let date = NSDate(timeIntervalSince1970:stringDate.doubleValue)

var outputFormat = NSDateFormatter()
outputFormat.locale = NSLocale(localeIdentifier:"ko_KR")
outputFormat.dateStyle = .MediumStyle
outputFormat.timeStyle = .MediumStyle
println("Result: \(outputFormat.stringFromDate(date))")

only one line of "import Cocoa"!

Playground error?

+4
source share
1 answer

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.

+4

All Articles