0

Part of my Code which is inside the class fetchData()

 @Published var deviceNmae : String = ""
 @Published  var deviceID : String = ""
    
    init(){
        self.deviceID = "t1199"
    }
    
    let urlString = "https://io.adafruit.com/\(deviceID)/"

error i am getting is

Cannot use instance member 'deviceID' within property initializer; property initializers run before 'self' is available

How can i solve this ? i looked into similar questions in stackOverflow but nothing seems to be working can someOne guide me with this

Karan D
  • 3
  • 2

1 Answers1

0

Two options:

  1. Use a lazy var:
lazy var urlString = "https://io.adafruit.com/\(deviceID)/"
  1. Use a computed property
var urlString: String { "https://io.adafruit.com/\(deviceID)/" }
Yonat
  • 4,382
  • 2
  • 28
  • 37