-2
let getLongijson: String = "67.0011"
let getlatijson: String = "24.8607"

let jsonlong = (getLongijson as NSString).doubleValue
let jsonlat = (getlatijson as NSString).doubleValue

Error i am Facing this Cannot use instance member 'getLongijson' within property initializer; property initializers run before 'self' is available

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
Rehan Meo
  • 61
  • 2
  • 9
  • post all your relevant code if your error message is that, that means that your issue is not related to String conversion, is about init instead – Reinier Melian May 14 '18 at 08:35
  • just this error i am facing – Rehan Meo May 14 '18 at 08:36
  • try to convert in sting to double – Rehan Meo May 14 '18 at 08:36
  • because longi late come form json the long late value is in string – Rehan Meo May 14 '18 at 08:37
  • if your error message is **Cannot use instance member 'getLongijson' within property initializer; property initializers run before 'self' is available** this means that you have an issue in your init method – Reinier Melian May 14 '18 at 08:37
  • thats why i need to convet string to double not converted – Rehan Meo May 14 '18 at 08:37
  • i am not using any init method – Rehan Meo May 14 '18 at 08:38
  • As pointed out above, the problem is not the conversion from string to double, but that you have properties whose initialization depends on other properties of the same type. – You'll find more than 40 similar question with answers with a SO search for `[swift] property initializers run before 'self' is available` – Martin R May 14 '18 at 08:46

1 Answers1

4

You like this to convert String into Double:

let getLongijson: String = "67.0011"
let getlatijson: String = "24.8607"

let jsonlong = Double(getLongijson)
let jsonlat = Double(getlatijson)
Jogendar Choudhary
  • 3,476
  • 1
  • 12
  • 26