1
下面這行SQLHandler.translateQuery(「Do mysql stuff」)拋出錯誤:'(String) - > String'不可轉換到'SQLHandler'。它爲什麼這樣做?先謝謝你。'(String) - > String'不可轉換爲'SQLHandler'
代碼1(用於無論何時何地需要)
var query: String = "mysql stuff"
SQLHandler.sendQuery(SQLHandler.translateQuery("domain and \(query)"))
碼2,SQLHandler.swift
import Foundation
class SQLHandler {
func translateQuery(queryToTranslate: String) -> String{
println(queryToTranslate)
return queryToTranslate.stringByReplacingOccurrencesOfString(" ", withString: "_", options: NSStringCompareOptions.LiteralSearch, range: nil)
}
func sendQuery(query: String){
println(query)
let url = NSURL(string: "url and query goes here")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in })
task.resume()
}
}