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")!
^~~
何か情報がありがとうございます。