我试图通过","分割从URL返回的字符串。但是当我尝试
时var tagArray = [String]()
if response.responseObject != nil {
let data = response.responseObject as NSData
let str = NSString(data: data, encoding: NSUTF8StringEncoding)!
self.tagArray = str.componentsSeparatedByString(", ") as String
println("response: \(self.tagArray)") //prints the HTML of the page
}
第self.tagArray = str.componentsSeparatedByString(", ") as String
行会引发错误"' String"不能转换为' [(字符串)]'"
任何人都知道如何正确地将字符串拆分成数组?
答案 0 :(得分:1)
违规行缺少广告投放中的[]
- 当您需要投射到{em>数组 String
时,您需要投放到Strings
{1}}:
var tagArray = [String]()
if response.responseObject != nil {
let data = response.responseObject as NSData
let str = NSString(data: data, encoding: NSUTF8StringEncoding)!
self.tagArray = str.componentsSeparatedByString(", ") as [String]
println("response: \(self.tagArray)") //prints the HTML of the page
}