2016-10-15 4 views
0

こんにちは、私はこの小さな遊び場を走らせようとしている問題を抱えています。プレイグラウンドから自分のファイルにコードを移動しようとするとエラーが発生する

let config = URLSessionConfiguration.default 
let session = URLSession(configuration: config) 
let url = URL(string: "http://reddit.com/r/globaloffensive/new")! 

let task = session.dataTask(with: url, completionHandler: { 
    (data, response, error) in 

    if error != nil { 
     print(error!.localizedDescription) 
    } else { 
     do { 
      if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any] { 
       dump(json) 
      } 
     } catch { 
      print("Error") 
     } 
    } 
}) 
task.resume() 

は、私は主にAPI呼び出しを作成する方法を把握しようとしているが、私は、独自のファイルでこれを実行し、

swift run test.swiftを実行したときに私が得る 独自のswiftファイルで実行するようにそれを得るために しよう

test.swift:1:14: error: use of unresolved identifier 'URLSessionConfiguration' 
let config = URLSessionConfiguration.default 
      ^~~~~~~~~~~~~~~~~~~~~~~ 
test.swift:2:15: error: use of unresolved identifier 'URLSession' 
let session = URLSession(configuration: config) 
       ^~~~~~~~~~ 
test.swift:3:11: error: use of unresolved identifier 'URL' 
let url = URL(string: "http://reddit.com/r/globaloffensive/new")! 
      ^~~ 

何か情報がありがとうございます。

答えて

0

あなたはFoundationフレームワークをインポートする必要があります。

import Foundation 
関連する問題