HungCLo HungCLo - 7 months ago 11
Swift Question

Instance member can not be used in swift

The project is to create a JSON object.

code is below :

public class RegisterIn {

private var appID : String = ""

private static let JK_appID : String = "appID"

init(appID: String) {
self.appID = appID
}

class getJSONObject : RegisterIn {
let jsonObject : [String : AnyObject] =
[
JK_appID : appID //< The following error shows on this line
]
}
}


This line always appears Error

Answer

appID is a instance variable but getJSONObject is a class method. So it will not work. You have to redesign it somehow.

Comments