成功在类定义中初始化为false
if (succeeded && (time>1000)){ errormessage += ";connection slow" }
时间初始化为
time = data[3].toInt()
数据在哪里
var data = split(raw_data) {class geocodeObject: NSObject {== ","}
而raw_data是一个字符串.
类定义:
init(lat: String,long:String,userstate:String) {
init定义:
class geocodeObject: NSObject {//A type to store the data from the Reverse GeoCoding API//Not a retrIEver//Optionslet API_KEY_TEXAS = "9e4797c018164fdcb9a95edf3b10ccfc"let DEV_MODE = true//Loading statusvar succeeded = falsevar errormessage = "Not Initalized" //Not nesscarilly a failure,Could be slow connectionvar loadstate: String?//Most important infovar street: String?; var housenumber: String?; var city: String?; var zip: String?//Metadatavar time: IntegerliteralType?; var statuscode: String?; var queryID: String?; var zip4: String?//Other geographical datavar entirestreet: String?; var state: String?init(lat: String,userstate:String) { //userstate: State provIDed by user //state: State provIDed by Reverse Geocoder var url: String? var extra: String? if DEV_MODE{ extra = "¬Store=true" } else{ extra = "" } url = "http://geoservices.tamu.edu/Services/ReverseGeoCoding/WebService/v04_01/http/default.aspx?lat="+lat+"&lon="+long+"&APIkey="+API_KEY_TEXAS+"&version=4.01" if (userstate == "nil"){ url = url! + extra! println("if") } else{ url = url! + "&state="+state!+extra! println("else") } let raw_data = retrIEveurl(url!) var data = split(raw_data) {init(lat: String,userstate:String) { super.init() ...== ","} //data[1] is API version used. statuscode = data[0]; queryID = data[2]; time = data[3].toInt(); entirestreet = data[4]; city = data[5] state = data[6]; zip = data[7]; zip4 = data[8] //Do street,housenumber,errormessage,succeeded if (state != userstate){ println("user state not equal to state") } var splittedstreet = split(entirestreet!){ == " "} housenumber = splittedstreet[0] street = splittedstreet[1] println(statuscode) //Error message handling switch String(statuscode!){ case "200": errormessage = "Success" case "400": errormessage = "UnkNown API key error" case "401": ... //Time handling if (succeeded && (time>1000)){ errormessage += ";connection slow" } } println("/GeoCodingAPIWrapper.swift/.geocodeObject.init: Not Implemented")}
(没有任何类型的超级init)
编辑:完整的代码与事情削减的方式
}
这是一段时间,但我发现的答案是你应该添加super.init()作为你的init块中的第一行这样我就摆脱了它,并且满足了错误的要求.据了解,这是您的变量在NSObject.init()中初始化,因此您可以在自定义init(_)块中使用分配的值
总结以上是内存溢出为你收集整理的class – ‘self’在super.init调用之前使用全部内容,希望文章能够帮你解决class – ‘self’在super.init调用之前使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)