我尝试使用此代码时,我的代码出现问题
import Foundation
import WebKit
let beaches: [String: Beach] = [
/* Mate Asher */
var i = 25
while i <= 30
{
i = i + 1 as string!
let urlPath = ("http://web.com/a.php?id=" + i + "&get=name")
let url: NSURL = NSURL(string: urlPath)!
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in})
let urlPath2 = ("http://web.com/a.php?id=" + i + "&get=area")
let url2: NSURL = NSURL(string: urlPath2)!
let session2 = NSURLSession.sharedSession()
let task2 = session.dataTaskWithURL(url2, completionHandler: {data2, response, error -> Void in})
let urlPath3 = ("web.com/a.php?id=" + i + "&get=longi")
let url3: NSURL = NSURL(string: urlPath3)!
let session3 = NSURLSession.sharedSession()
let task3 = session.dataTaskWithURL(url3, completionHandler: {data3, response, error -> Void in})
"a": Beach(title: data, desc: data2, latitude: 33.080512, longitude: data3),
}
]
我得到var行的错误 &#34;容器文字中的预期表达式&#34; 有人可以帮忙吗??
答案 0 :(得分:2)
创建数组或字典时,不应该做任何类型的循环/条件制作代码块。为此,你需要在外面执行那段代码,创建一个变量并使用它。